You can call the function directly, no need to use ahkExec.
Also no need to load the script every time you call the function, load once, call as often as you want.
You can also create Bound functions for different amount of parameters to use for all functions:
Code: Select all
script:=
(
"#Persistent
test(v1, v2)
{
if v1 + v2 = 3
Return test2()
Else
Return 0
}
test2()
{
Return 1 + 2
}"
)
hDll := DllCall("LoadLibrary","Str",dll:="D:\Scratch\Program Files\AutoHotKey\AutoHotkey 1\x64w\AutoHotkey.dll","Ptr")
DllCall(dll "\ahktextdll", "Str", script, "Str", "", "Str", "")
ahkFunction:=DllCall.Bind(hahkFunction:=DllCall("GetProcAddress","Ptr",hDll,"AStr","ahkFunction","PTR"),"Str",,"Str","","Str",","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str") ; no params
ahkFunction1:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str") ; 1 param
ahkFunction2:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str") ; 2 params
ahkFunction3:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str") ; 3 params
ahkFunction4:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str") ; 4 params
ahkFunction5:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","Str","","Str","","Str","","CDecl Str") ; 5 params
ahkFunction6:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","Str","","Str","","CDecl Str") ; 6 params
ahkFunction7:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","Str","","CDecl Str") ; 7 params
ahkFunction8:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","Str","","CDecl Str") ; 8 params
ahkFunction9:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str","","CDecl Str") ; 9 params
ahkFunction10:=DllCall.Bind(hahkFunction,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"Str",,"CDecl Str") ; 10 params
MsgBox ahkFunction2("test","1","2")
MsgBox ahkFunction2("test","4","5")