Function DllCall
Function DllCall
Function Reference
DllCall
Dynamically calls a function in a DLL.
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )
Parameters
The filename of the DLL to use. e.g. "user32.dll". A handle obtained from DllOpen can also be used (See
dll
Remarks).
function The name, eg. "MessageBox" or the ordinal value, e.g. 62, of the function in the DLL to call.
Type Details
UINT_PTR,
ULONG_PTR,
an unsigned integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt.
DWORD_PTR,
WPARAM
LPCSTR/LPSTR STR
LPCWSTR/LPWSTR WSTR
LPVOID PTR
LPxyz xyz*
HINSTANCE HANDLE
HRESULT LONG
LONGLONG/LARGE_INTEGER INT64
ULONGLONG/ULARGE_INTEGER UINT64
SIZE_T ULONG_PTR
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.
Return Value
Success: an array. See remarks.
Failure: sets the @error flag to non-zero.
@error: 1 = unable to use the DLL file,
2 = unknown "return type",
3 = "function" not found in the DLL file,
4 = bad number of parameters,
5 = bad parameter.
https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm 2/4
17/7/2020 Function DllCall
Remarks
If a dll filename is given then the DLL is automatically loaded and then closed at the end of the call. If you want to manually
control the loading and unloading of the DLL then you should use DllOpen() and DllClose() and use a handle instead of a
filename in this function.
By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type.
DllCall("SQLite.dll", "int:cdecl", "sqlite3_open", "str", $sDatabase_Filename , "long*", 0).
By default, AutoIt tries to use the ANSI version of a function name, i.e. MessageBoxA is attempted when MessageBox is given as
the function name. To call the unicode version use MessageBoxW.
Related
DllCallbackFree, DllCallbackGetPtr, DllCallbackRegister, DllClose, DllOpen, DllStructCreate, DllStructGetPtr
Example
Example 1
Example 2
#include <MsgBoxConstants.au3>
If $hWnd = 0 Then
; Timeout occured.
Exit MsgBox($MB_SYSTEMMODAL, Default, "Unable to start notepad!")
EndIf
Local $aResult = DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "str", "", "i
WinClose($hWnd)
Example 3
#include <MsgBoxConstants.au3>
; Run the PickIconDlg - '62' is the ordinal value for this function
DllCall("shell32.dll", "none", 62, _
"hwnd", 0, _
"struct*", $tString, _
"int", $iStructsize, _
"struct*", $tIconIndex)
$sFileName = DllStructGetData($tString, 1)
Local $iIconIndex = DllStructGetData($tIconIndex, 1)
https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm 4/4