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\ahktextdll", "Str", "Script", "Str", "Parameters", "Str", "Title", "CDecl UPTR")
Command  Example: DllCall "AutoHotkey.dll\ahktextdll", "Str", "MsgBox From Thread", "Str",, "Str",, "CDecl UPTR"
Function Example: hThread := DllCall("AutoHotkey.dll\ahktextdll", "Str", "MsgBox From Thread" ,"Str",, "Str",, "PTR")



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

Script (optional)

String containing new AutoHotkey script 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


dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
DllCall(dllpath "\ahktextdll","Str","MsgBox Hello World!","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("MsgBox Hello World!")
While dll.ahkReady()
  Sleep 100 ; wait for the thread to exit