Dynamically calls a function in a DLL.
DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]] )
Parameters
| dll | The filename of the DLL to use. e.g. "user32.dll". A handle obtained from DllOpen can also be used (See Remarks). |
| return type | The return type of the function (see below). |
| function | The name, eg. "MessageBox" or the ordinal value, e.g. 62, of the function in the DLL to call. |
| type | [optional] The type of the parameter (see remarks). |
| param | [optional] The actual parameter (see remarks). |
| Type | Details |
| none | no value (only valid for return type - equivalent to void in C) |
| byte | a 8 bit integer |
| ubyte | an unsigned 8 bit integer |
| short | a 16 bit integer |
| ushort | an unsigned 16 bit integer |
| dword | an unsigned 32 bit integer |
| udword | an unsigned 32 bit integer |
| int | a 32 bit integer |
| uint | an unsigned 32 bit integer |
| long | a 32 bit integer |
| ulong | an unsigned 32 bit integer |
| int64 | a 64 bit integer |
| uint64 | an unsigned 64 bit integer |
| str | an ANSI string (cannot be more than 65536 chars). |
| wstr | a UNICODE wide character string (converted to/from an ANSI string during the call if needed). Cannot be more than 65536 chars. |
| hwnd | a window handle (pointer) |
| ptr | a general pointer (void *) |
| float | a single precision floating point number |
| double | a double precision floating point number |
| lresult/int_ptr/long_ptr | an integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt. |
| lparam/int_ptr/long_ptr | an integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt. |
| wparam/uint_ptr/ulong_ptr | an unsigned integer big enough to hold a pointer when running on x86 or x64 versions of AutoIt. |
| * | Add * to the end of another type to pass it by reference. For example "int*" passes a pointer to an "int" type. |
| WINDOWS API Type | AutoIt Type |
| LPCSTR/LPSTR | str |
| LPCWSTR/LPWSTR | wstr |
| LPVOID | ptr |
| HWND | hwnd |
| WPARAM | wparam |
| LPARAM | lparam |
| DWORD | dword |
| LPDWORD | dword* |
| HANDLE/HINSTANCE | ptr |
| LONGLONG/LARGE_INTEGER | int64 |
| ULONGLONG/ULARGE_INTEGER | uint64 |
| UINT_PTR | wparam |
| LONG_PTR | lparam |
Return Value
| Success: | @error = 0. |
| Failure: | @error = 1 unable to use the DLL file, |
| @error = 2 unknown "return type", | |
| @error = 3 "function" not found in the DLL file. |
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.
Related
DllCallbackFree, DllCallbackGetPtr, DllCallbackRegister, DllOpen, DllClose, DllStructCreate, DllStructGetPtr
Example
; *******************************************************
; Example 1 - calling the MessageBox API directly
; *******************************************************
$result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
; *******************************************************
; Example 2 - calling a function that modifies parameters
; *******************************************************
$hwnd = WinGetHandle("[CLASS:Notepad]")
$result = DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hwnd, "str", "", "int", 32768)
msgbox(0, "", $result[0]) ; number of chars returned
msgbox(0, "", $result[2]) ; Text returned in param 2
; *******************************************************
; Example 3 - Show the Windows PickIconDlg
; *******************************************************
$sFileName = @SystemDir & '\shell32.dll'
; Create a structure to store the icon index
$stIcon = DllStructCreate("int")
$stString = DLLStructCreate("wchar[260]")
$structsize = DllStructGetSize($stString)/2
DllStructSetData($stString, 1, $sFileName)
; Run the PickIconDlg - '62' is the ordinal value for this function
DllCall("shell32.dll", "none", 62, "hwnd", 0, "ptr", DllStructGetPtr($stString), "int", $structsize, "ptr", DllStructGetPtr($stIcon))
$sFileName = DllStructGetData($stString, 1)
$nIconIndex = DllStructGetData($stIcon, 1)
; Show the new filename and icon index
Msgbox(0, "Info", "Last selected file: " & $sFileName & @LF & "Icon-Index: " & $nIconIndex)