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)
The name of the variable in which to store the DynaCall object which is used to call the dll 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.
For definition you will need to use the short version of DllCall types.
DllCall | DynaCall equivalent |
Int | i |
Str | s |
AStr | a |
WStr | w |
Short | h |
Char | c |
Float | f |
Double | d |
PTR | t |
Int64 | i6 |
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
This is best explained in following example.
IsSuspended := A_IsSuspended AHKCMD:=DynaCall("SendMessage", ["t=tuitt", 3], A_ScriptHwnd, 0x111) ; so for AHKCMD, the order of SendMessage usual parameters (HWND hWnd, UINT Msg, WPARAM wParam,LPARAM lParam) is changed to (WPARAM wParam, HWND hWnd, UINT Msg, LPARAM lParam) when calling AHKCMD() AHKCMD(65305) ; suspend script ; AHKCMD(65305, A_ScriptHwnd, 0x111, 0) ; same as above ; DllCall("SendMessage", "PTR", A_ScriptHwnd, "UInt", 0x111, "PTR", 65305, "PTR", 0) ; same as above MsgBox IsSuspended " != " A_IsSuspended
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.
Base and __Class are reserved properties and DynaCall cannot be invoked using them as parameter with dot (.) syntax, instead use MyDynaCall["base"] syntax!
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