It is possible to do what you wanted. I wanted something similar earlier, here's a demonstration.
Runner.ahk:
Code: Select all
;@Ahk2Exe-Base %A_AhkPath%, Main.exe
;@Ahk2Exe-ResourceID #1
;@Ahk2Exe-AddResource *6 Main.ahk, MAIN_SCRIPT
#NoTrayIcon
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
ScriptName := "Main"
ResRead(Code, "MAIN_SCRIPT")
Shell := ComObjCreate("WScript.Shell")
Name := "\\.\pipe\" ScriptName ".exe"
Pipe := []
Loop 2
{
Pipe[A_Index] := DllCall("CreateNamedPipe"
, "Str", Name
, "UInt", 2, "UInt", 0
, "UInt", 255, "UInt", 0
, "UInt", 0, "UPtr", 0
, "UPtr", 0, "UPtr")
}
Exec := Shell.Run("""" A_ScriptFullPath """ /restart /script /CP65001 " Name)
DllCall("ConnectNamedPipe", "UPtr", Pipe[1], "UPtr", 0)
DllCall("ConnectNamedPipe", "UPtr", Pipe[2], "UPtr", 0)
FileOpen(Pipe[2], "h", "UTF-8").Write(Code)
Loop 2
DllCall("CloseHandle", "UPtr", Pipe[A_Index])
ExitApp
; SKAN http://www.autohotkey.com/board/topic/57631-crazy-scripting-resource-only-dll-for-dummies-36l-v07/?p=609282
ResRead( ByRef Var, Key )
{
VarSetCapacity( Var, 128 ), VarSetCapacity( Var, 0 )
If ! ( A_IsCompiled )
{
FileGetSize, nSize, %Key%
FileRead, Var, *c %Key%
Return nSize
}
If hMod := DllCall( "GetModuleHandle", UPtr,0 , Ptr)
If hRes := DllCall( "FindResource", Uptr,hMod, Str,Key, UInt,6 , Ptr)
If hData := DllCall( "LoadResource", UInt,hMod, UPtr,hRes , Ptr)
If pData := DllCall( "LockResource", UInt,hData, Ptr )
{
VarSetCapacity( Var, nSize := DllCall( "SizeofResource", UInt,hMod, UInt,hRes ) )
DllCall( "RtlMoveMemory", Str,Var, UInt,pData, UInt,nSize )
Var := StrGet(&Var, nsize, "UTF-8")
Return, StrLen(Var)
}
Return 0
}
Main.ahk: (will be statically embedded into the final exe)
Addon.ahk: (can be dynamically written, not embedded into the final exe)
The trick is to use the compiled exe as an AutoHotkey interpreter with the
/script switch, this way you can run the script as if you're running the source file. To use, compile Runner.ahk instead of Main.ahk. Ahk2exe will embed Main.ahk into the compiled exe, but when it is run, the Main code embedded is executed dynamically, therefore including any ahk you want at runtime.