Exported function that allows calling a function in script currently executed by AutoHotkey module.
Paramenters can be strings only as well as return value.

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

Function Example: OutputVar := DllCall("AutoHotkey.dll\ahkFunction", "Str", "FuncName"[, "Str", Arg1 , ..., "Str",Arg10], "Str")
                  OutputVar := DllCall("AutoHotkey.exe\ahkFunction", "Str", "FuncName"[, "Str", Arg1 , ..., "Str",Arg10], "Str")



The name of the variable to store the functions returned value as string, on failure empty string is stored.


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)


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


ahkPostFunction, ahkFindFunc, DllCall


dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahktextdll","Str","#Persistent`nMyFunc(param){`nSleep 10000`nMsgBox `% param`n}","Str","","CDecl") ; start a new thread, just the function.
Msgbox % DllCall(dllpath "\ahkFunction","Str","MyFunc","Str","Hello World!","CDecl Str") ; call the function.

; Same example like above using internal AutoHotkey.dll
dll:=AhkThread("#Persistent`nMyFunc(param){`nSleep 10000`nMsgBox `% param`n}")
MsgBox % dll.ahkFunction["MyFunc","test"]