Exported function to create additional AutoHotkey thread in current process from a file on disk or network.
If a thread is already executed it will terminated before new thread starts.
Note you will need to load AutoHotkey.dll module using LoadLibrary before you can use this function, see Example.
This function is only available in AutoHotkey.dll

OutputVar := DllCall("AutoHotkey.dll\ahkdll", "Str", "FileName", "Str", "Parameters", "Str", "Title", "CDecl UPTR")
Command  Example: DllCall "AutoHotkey.dll\ahkdll", "Str", "FileName.ahk", "Str",, "Str",, "CDecl UPTR"
Function Example: hThread := DllCall("AutoHotkey.dll\ahkdll", "Str", "FileName.ahk" ,"Str",, "Str",, "PTR")



The name of the variable in which to store the handle of newly created thread.

FileName.ahk (optional)

New AutoHotkey script saved on disk or network to be executed in AutoHotkey.dll. When omitted, following script is used:


Parameters (optional)

Command line parameters that will be available in built-in variable A_Args object.

Title (optional)

Title for the dll thread (by default filename) that will be shown in MsgBox, Gui... when no Title is given.

General Remarks

ahkdll behaves different when instead of MyScript.ahk an empty string or 0 is passed:

When exe was started with command line parameters, the dll will be able to grab the parameters and use same library as well as A_ScriptDir and A_ScriptFullPath as the executable. When executable is compiled, the path of the executable will be used.


ahktextdll, AutoHotkey.dll, AhkThread, Threads, DllCall


dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahkdll","Str",A_ScriptDir "\MyDllScript.ahk","Str","","CDecl") ; start a new thread from file.
While DllCall(dllpath "\ahkReady")
  Sleep 100 ; wait for the thread to exit

; Same Example like above using included AutoHotkey.dll
dll:=AhkThread(A_ScriptDir "\MyDllScript.ahk","",true)
While dll.ahkReady()
  Sleep 100 ; wait for the thread to exit