Function Reference

DllCall

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. eg. "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 of the function in the DLL to call, eg. "MessageBox"
type [optional] The type of the parameter (see remarks).
param [optional] The actual parameter (see remarks).

 

Return Value

See remarks.

 

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.

You can have as many "types" and "param" as you like. See the examples below that use a number of parameters.

Valid Types are:

Type Details
none no value (only valid for return type - equivalent to void in C)
short a 16 bit integer
int a 32 bit integer
long a 32 bit integer
short_ptr a pointer to a 16 bit integer
int_ptr a pointer to a 32 bit integer
long_ptr a pointer to a 32 bit integer
str a string
wstr a wide character string (converted to/from an ANSI string during the call)
hwnd a window handle
ptr a general pointer (void *)

If the function call fails then @error is set to 1. 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).
$return[0] = function return value
$return[1] = param1
$return[2] = param2
...
$return[n] = paramn

 

Related

None.

 

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("Untitled - 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