The Win32-common library provides a define callback macro to make it easy to define callback functions without the application programmer needing to use the FFI define c-callable-wrapper macro directly. It is used like this:
define callback WndProc :: <WNDPROC> = my-window-function;
This says that WndProc is being defined as a C function pointer of type <WNDPROC>, which when called from C causes the Dylan function my-window-function to be run. The Dylan function will be defined normally using define method or define function, and it is the responsibility of the programmer to ensure that its argument signature is consistent with what <WNDPROC> requires. For example:
define method my-window-function(
hWnd :: <HWND>, // window handle
message :: <integer>, // type of message
uParam, // additional information
lParam) // additional information
=> return :: <integer>;
...
Note that the uParam and lParam arguments might receive values of either type <integer> or <machine-word>, so it may be best not to specialize them. Often these values are not used directly anyway, but are passed to other functions (such as LOWORD and HIWORD) which have methods for handling either representation.
The other types of function supported by define callback are dialog functions (<DLGPROC>) and dialog hooks (<LP...HOOKPROC>), both of which have the same argument types as a window function, but return a <boolean>. (The dialog hook functions are actually declared in COMMDLG.H as returning a UINT, but the value is always supposed to be TRUE or FALSE, so the Dylan callback interface has been implemented using BOOL instead.)