Function Reference


Dynamically calls a function at a specific memory address.

DllCallAddress ( "return type", address [, type1, param1 [, type n, param n]] )


return type The return type of the function (see below).
address The address of a function. If this value is invalid your script will crash!
type1 [optional] The type of the parameter (see remarks).
param1 [optional] The actual parameter (see remarks).
type n [optional] The type of the nth parameter (see remarks).
param n [optional] The actual nth parameter (see remarks).

Valid Types are:

Type Details
NONE no value (only valid for return type - equivalent to void in C)
BYTE an unsigned 8 bit integer
BOOLEAN an unsigned 8 bit integer
SHORT a 16 bit integer
USHORT an unsigned 16 bit integer
WORD an unsigned 16 bit integer
INT a 32 bit integer
LONG a 32 bit integer
BOOL a 32 bit integer
UINT an unsigned 32 bit integer
ULONG an unsigned 32 bit integer
DWORD an unsigned 32 bit integer
INT64 a 64 bit integer
UINT64 an unsigned 64 bit integer
PTR a general pointer (void *)
HWND a window handle (pointer)
HANDLE an handle (pointer)
FLOAT a single precision floating point number
DOUBLE a double precision floating point number
INT_PTR, LONG_PTR, LRESULT, LPARAM an integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.
UINT_PTR, ULONG_PTR, DWORD_PTR, WPARAM an unsigned integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.
STR an ANSI string (a minimum of 65536 chars is allocated).
WSTR a UNICODE wide character string (a minimum of 65536 chars is allocated).
STRUCT structure created with DllStructCreate()
* Add * to the end of another type to pass it by reference. For example "int*" passes a pointer to an "int" type.

Conversions from Windows API types to AutoIt types:

WINDOWS API Type AutoIt Type
LPxyz xyz*
To use nested structures inside a structure you must re-define the nested structure. For example, a structure containing 2 POINT structures ("long;long") would be declared as "long;long;long;long". The first two long values correspond to the first POINT structure and the second two values correspond to the second POINT structure.

For more Windows API types see MSDN.

Return Value

Success: an array. See remarks.
Failure: sets the @error flag to non-zero.
@error: 2 = unknown "return type",
4 = bad number of parameters,
5 = bad parameter


By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type.

If the function call fails then the @error flag is set to non-zero.
Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified when passed by reference).
$return[0] = function return value
$return[1] = param1
$return[2] = param2
$return[n] = paramn

Special Note: This is an advanced function. Incorrect use of this function may cause AutoIt to crash. Before using this function make sure DllCall() doesn't do what you need.


DllCall, DllCallbackFree, DllCallbackGetPtr, DllCallbackRegister, DllClose, DllOpen, DllStructCreate, DllStructGetPtr


#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


Func Example()
    ; Enable GUI event mode.
    Opt("GUIOnEventMode", 1)

    ; Create a simple GUI.
    Local $hWnd = GUICreate("DllCallAddress Example")

    ; Register the close event handler.
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")

    ; Show the GUI.
    GUISetState(@SW_SHOWNORMAL, $hWnd)

    ; Get a pointer to the window's WindowProc().
    Local $pWndProc = _WinAPI_GetWindowLong($hWnd, $GWL_WNDPROC)

    ; Tell the user what is about to happen.
    MsgBox($MB_SYSTEMMODAL, "DllCallAddress Example Msg", "When you press OK the test window will close.")

    ; Explicitly generate a WM_CLOSE event and pass it directly to the WindowProc().
    ; This should never be done in a real application (Use _SendMessage() instead) but
    ; it demonstrates how to use the function.
    DllCallAddress("LRESULT", $pWndProc, "HWND", $hWnd, "UINT", $WM_CLOSE, "WPARAM", 0, "LPARAM", 0)
EndFunc   ;==>Example

Func OnClose()
    MsgBox($MB_SYSTEMMODAL, "DllCallAddress Example Msg", "Close event received, the test window should now be closed.")
EndFunc   ;==>OnClose