ahkPostFunction

Exported function that allows calling a function in script currently executed by AutoHotkey module without waiting for the function to return.
Paramenters can be strings only.


OutputVar := ahkPostFunction("FuncName" , Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10)
Function Example: OutputVar := DllCall("AutoHotkey.dll\ahkPostFunction", "Str", "FuncName"[, "Str", Arg1 , ..., "Str",Arg10], "Str")
                  OutputVar := DllCall("AutoHotkey.exe\ahkPostFunction", "Str", "FuncName"[, "Str", Arg1 , ..., "Str",Arg10], "Str")

Parameters

OutputVar

The name of the variable to store 0 if function was found or -1 if functon was not found.

FuncName

The name of the function to call.

Arg1, ..., Arg10

You can pass up to 10 parameters to the function. Note all parameters need to be Strings or NULL / 0 if you want to omit parameter (use function default parameters)

Return Value

If a function was found and called it returns 1 (true), otherwise 0 (false).

Remarks

Note that Function will not run if #MaxThreads limit is reached.

Related

ahkFunction, ahkFindFunc

Examples

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahktextdll","Str","#Persistent`nMyFunc(param){`nSleep 1000`nMsgBox `% param`n}","Str","","CDecl") ; start a new thread, just the function.
DllCall(dllpath "\ahkPostFunction","Str","MyFunc","Str","Hello World!","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl") ; call the function.
Sleep 5000 ; wait 5 seconds and exit
 
 ; Same example like above using included AutoHotkey.dll
 dll:=AhkThread("#Persistent`nMyFunc(param){`nSleep 1000`nMsgBox `% param`n}")
 dll.ahkPostFunction["MyFunc","Hello World!"]
 Sleep 5000