Dynamically include code in compiled .exe (Requires AutoHotkey_H)

Helpful script writing tricks and HowTo's
Posts: 1
Joined: 24 Aug 2016, 07:48
Location: Australia

Dynamically include code in compiled .exe (Requires AutoHotkey_H)

27 Aug 2016, 07:34


I am a light user of AHK, but impressed by its simplicity and usefulness. About a year ago, I wanted to create a compiled utility for a USB keyboard that made it more user-friendly under Windows. The utility would implement some default behaviours, but allow the user to change and extend these as needed.

To achieve this, I wanted a single executable (no .dll) that included all the base functionality and default settings, but that could then dynamically load extra AHK scripts and bind hot keys as desired.

Much forum searching and reading ensued until I was reasonably confident what I wanted to do could not be achieved under vanilla AutoHotkey, but required the AutoHotkey_H variant. Many more hours of trial and error were spent before I had working code. This was primarily due to my own lack of knowledge, and not quite being able to grasp what was being said in the forums. This tutorial is what I wish I had discovered back then. :)

Install AutoHotkey_H
The aim here was to install AutoHotkey_H and be able to generate a compiled binary that included it instead of vanilla AutoHotkey.

1) Download and install AutoHotkey
Note which version you choose - ANSI 32-bit, Unicode 32-bit or Unicode 64-bit.

2) Download AutoHotkey_H

3) Extract AutoHotkey_H (ahkdll-v1-release-master.zip) in a temp directory.

4) Dending on which version of AutoHotkey you installed earlier, copy AutoHotkey.exe from:
ahkdll-v1-release-master\Win32a (ANSI 32-bit)
ahkdll-v1-release-master\Win32w (Unicode 32-bit)
ahkdll-v1-release-master\x64w (Unicode 64-bit)
to c:\Program Files\AutoHotkey\AutoHotkey.exe

5) Copy all the contents of
to C:\Program Files\AutoHotkey\Compiler

That's it! You should now be able to run AHK scripts using additional functions from AutoHotkey_H.


You can now dynamically load a AHK file from your main script using:

Code: [Select all] [Download] GeSHi © Codebox Plus

DllCall(A_AhkPath . "\addFile", "str", "path\to\your\DynamicScript.ahk", "uchar", 1, "uchar" , 0, "Cdecl UInt") ; Requires AutoHotkey_H


To compile your main script, run the following from the command line (cmd.exe):

Code: [Select all] [Download] GeSHi © Codebox Plus

"C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.ahk" /bin "C:\Program Files\AutoHotkey\AutoHotkey.exe" /in MainScript.ahk /out MainScript.exe

There you have it! A summary of what took me many hours to discover. Apologies if its stating the obvious for some - if it helps one or two fellow coders, then it's done its job :D
Posts: 2221
Joined: 09 Oct 2013, 10:31

Re: Dynamically include code in compiled .exe (Requires AutoHotkey_H)

27 Aug 2016, 13:28

good job. basically this allows you to create a plugin system where you can distribute other .ahk files and load them as plugins into your main script this way

here's the help page explaining the addFile function that you're using:

and heres the help page for all of the AHK_H differences

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 7 guests