DllCallbackCreate

Associates a user defined function or subroutine with a callback handle.

Syntax:

DllCallbackCreate (UDF-name, return-type, parameter-types)

Parameters:

(s) UDF-name: name of previously defined user defined function or subroutine.

(s) return-type: expected return data type. May be one of WORD, LONG, VOID, or DOUBLE.

(s) parameter-types: Space delimited list of the expected types of each parameter for the WORD, LPSTR, LPWSTR, LPNULL, LONG or DOUBLE.

Returns:

(i) callback handle.

 

The returned handle can be used with DllCall or DllCallCdecl when calling external DLL functions that require a pointer to an application-defined callback function as a parameter.  The UDF/UDS associated with the handle is executed when the external DLL function calls the application-defined function.

The associated UDF/UDS must have the same number of parameters that the external DLL function expects for the application-defined callback.  The parameter types and return type specified in the second and third parameters must be compatible with the documented types for the application-defined callback function.

Use the callback handle with DllCall or DllCallCdecl by passing the handle to the external function with the new 'callback' parameter type specifier. A maximum of 512 callback handles can be active at one time.

Example:
; DllCall with Callback example.
#DefineFunction udfEnumWindowsProc(hwnd, lparam)
      ; This callback will run until:
      ;   Callback returns FALSE
      ;   There are no more top level windows to enumerate
      maxsize = 256
      lptitle = BinaryAlloc(maxsize)
      BinaryEodSet(lptitle, 0)
      length = DllCall(DirWindows(1):'user32.dll', long:'GetWindowTextA',long:hwnd,lpbinary:lptitle,long:maxsize)
      If length>1
         BinaryEodSet(lptitle, length)
         title = BinaryPeekStr(lptitle, 0, length)
         If StrIndex( title, lparam, 1, @FWDSCAN )
            ret = AskYesNo( lparam:' window exists!', 'Close this window? [':title:']' )
            If ret == @YES Then WinClose(title) ;Close Window
         EndIf
      EndIf
      BinaryFree(lptitle)
      Return @TRUE
#EndFunction
; Locates window and closes it
lookfortitle = 'Notepad'
ShellExecute('Notepad.exe', '', '', @NORMAL, '')
TimeDelay(1)
cbhandle = DllCallbackCreate('udfEnumWindowsProc', 'LONG', 'LONG LPSTR')
ret = DllCall( DirWindows(1):'user32.dll', long:'EnumWindows',callback:cbhandle,lpstr:lookfortitle)
DllCallbackDestroy(cbhandle)
Exit
See Also:

DataCast, DllCall, DllCallbackDestroy, DllCallCdecl, DllCall Additional information, Binary Operations, DllLoad, DllFree, DllHwnd, DllHinst, IntControl 96