Next Previous Up Top Contents Index

2 The Functional Developer Win32 API Libraries

2.8 Dealing with the C function WinMain

In C, the programmer has to supply a WinMain function as the main program for a GUI application, but in Dylan there is no main program as such. The beginning of execution is indicated simply by a top-level function call expression; this needs to be at the bottom of the last file listed in the project file. The Win32-Kernel and Win32-User libraries export functions to obtain the values which would have been the arguments to WinMain:

application-instance-handle() => <HINSTANCE>
application-command-line() => <string>  
                              // arguments without program name
application-show-window() => <integer>    // one of $SW-...

There is no accessor provided for the WinMain previous instance parameter because on Win32, that parameter is always null, even for Win32s as well as NT and Windows 95.

The program can be terminated, with an exit code, by calling either the Win32 ExitProcess function or the exit-application function in Functional Developer's Operating-system library. The latter method is preferred if the application might actually be run as part of another process.

The start of an application program might look something like this:

define method my-main ()
  let hInstance :: <HINSTANCE> = application-instance-handle();
  let wc :: <PWNDCLASS> = make(<PWNDCLASS>);
  wc.style-value := 0;
  wc.lpfnWndProc-value := MainWndProc;

... RegisterClass(wc); let hWnd = CreateWindow( ... ); ShowWindow(hWnd, application-show-window()); UpdateWindow(hWnd); let msg :: <PMSG> = make(<PMSG>);

while ( GetMessage(msg, $NULL-HWND, 0, 0) ) TranslateMessage(msg); DispatchMessage(msg); end; ExitProcess(msg.wParam-value); end method my-main;

my-main(); // this is what initiates execution.

For a complete example program, see

Examples\Win32\windows-ffi-example\example.dylan 

in the Functional Developer installation directory.


C FFI and Win 32 Reference - 31 MAR 2000

Next Previous Up Top Contents Index