DynaCall

Build in function, similar to DllCall but works with DllCall structures and uses Object syntax. It is often faster than DllCall, easier to use and it saves a lot of typing and code.

OutputVar := DynaCall("DllFile\Function", "ParameterDefinition", Default1, Default2, Default3, ...)
Function Example: TrueSleep := DynaCall("kernel32\Sleep", "ui", 100)
Calling the Func: TrueSleep(1000)

Parameters

OutputVar

The name of the variable in which to store the DynaCall object which is used to call the dll function.

[DllFile\]Function

The DLL or EXE file name followed by a backslash and the name of the function. For example: "MyDLL\MyFunction" (".dll" is default and can be omitted). If an absolute path isn't specified, DllFile is assumed to be in the system's PATH or A_WorkingDir.

DllFile may be omitted when calling a function that resides in User32.dll, Kernel32.dll, ComCtl32.dll, or Gdi32.dll. For example, "User32\IsWindowVisible" produces the same result as "IsWindowVisible".

If no function can be found by the given name, a "W" (Unicode) suffix is automatically appended. For example, "MessageBox" is the same as "MessageBoxW".

This parameter may also consist solely of an an integer, which is interpreted as the address of the function to call. Sources of such addresses include COM and Callback.

ParameterDefinition

For definition you will need to use the short version of DllCall types.

DllCall DynaCall equivalent
Inti
Strs
AStra
WStrw
Shorth
Charc
Floatf
Doubled
PTRt
Int64i6
CDecl Use == instead of =, for example "t==uis".
U prefix and * or p This is supported as well, for example: "ui=ui*s", "ui=uips"

The syntax for parameter definition is [  Return type   =[=]    ]   ParamType    ParamType    ParamType   ...
You can have any amount of space or tabs between parameters, those will be simply ignored.

Changing order of parameters

Default Value

The default value to use when the parameter is omitted in function call.
Note, this will be always the original order of parameters as specified in ParameterDefinition.

Remarks

Base and __Class are reserved properties and DynaCall cannot be invoked using them as parameter with dot (.) syntax, instead use MyDynaCall["base"] syntax!

Examples

Msg:=DynaCall("MessageBox",["ui=tssui",2,3],0,"DefaultText","DefaultTitle") ; define the DynaCall object.
Msg ; Call using default parameters
Msg.NewText ; Call passing one parameter
Msg.NewText("NewTitle") ; Call passing 2 parameters
Msg("NewText","NewTitle") ; Call passing 2 parameters, same as above

Related

#DllImport, WinApi