Function Reference


Creates a user-defined DLL Callback function.

DllCallbackRegister ( "function", "return type", "params" )


function The name of the User Defined Function to call.
return type The return type and calling convention of the function (see DllCall).
params A semi-colon separated list of parameters that will be passed to this function. See Remarks.

Return Value

Success: a dll "handle" to be used with DllCallbackGetPtr() and DllCallbackFree() functions.
Failure: 0 if error occurs.


Uses all DllCall() types except "struct".
When finished working with a callback, call the DllCallbackFree() function to close it. AutoIt normally closes all files upon termination, but explicitly calling DllCallbackFree() is still a good idea.


DllCall, DllCallbackFree, DllCallbackGetPtr


#include <MsgBoxConstants.au3>

; Create callback function.
Local $hHandle = DllCallbackRegister("_EnumWindowsProc", "int", "hwnd;lparam")

; Call EnumWindows.
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle), "lparam", 10)

; Delete callback function.

; Callback Procedure
Func _EnumWindowsProc($hWnd, $lParam)
        ; If the Title is empty or if the window is not visible then continue enumeration.
        If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1

        Local $iRes = MsgBox(($MB_OKCANCEL + $MB_SYSTEMMODAL), _
                        WinGetTitle($hWnd), "$hWnd=" & $hWnd & @CRLF & _
                        "$lParam=" & $lParam & @CRLF & _
                        "$hWnd(type)=" & VarGetType($hWnd))

        If $iRes <> $IDOK Then Return 0 ; Cancel/Close button clicked, return 0 to stop enumeration.

        Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc