My current implementation of AHKThread utilizes the .ahk file, which will not work moving forward due to everything being compiled, as my understanding is that AhkThread() can not be utilized on .exe's.
Copying the code directly into the script does not appear to resolve the issue, due to #Include not compiling as expected if inside of parenthesis for the AHKThread() string with the methods I have attempted.
; This works wonderfully when not compiled, but breaks once compiled as the compiler doesn't properly include the file.
; Line Text: #Include <testFolder\testTwo>
; Error: Function library not found.
#Include <testFolder\defaultObject> ; e.g. defaultObject := { "testValue": 66 }
CritObj := CriticalObject(defaultObject)
thread := AHKThread("
(
#Include <testFolder\testTwo>
)", &CritObj "", "threadName_2", false)
; Received a VarSetCapacity error as explained in latest github issue opened by myself (https://github.com/HotKeyIt/ahkdll-v2-release/issues/15)
; I am not positive that you can pass Critical Objects via BinRun
#Include <testFolder\defaultObject> ; e.g. defaultObject := { "testValue": 66 }
CritObj := CriticalObject(defaultObject)
file:=FileRead("testTwo","RAW")
PID := BinRun(&file, &CritObj "")
; This runs the script immediately in-line, it does not care that I'm passing it to AHKThread (it never establishes a second thread)
; This also does not resolve the issue of needing to import Library files into the second thread (e.g. #Include <utils>)
#Include <testFolder\defaultObject> ; e.g. defaultObject := { "testValue": 66 }
CritObj := CriticalObject(defaultObject)
script :=
(
MsgBox("test")
)
thread := AHKThread(script, &CritObj "", "threadName_2", false)
Last edited by Deafwave on 28 Aug 2020, 22:59, edited 1 time in total.
; This works wonderfully when not compiled, but breaks once compiled as the compiler doesn't properly include the file.
; Line Text: #Include <testFolder\testTwo>
; Error: Function library not found.
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)
thread := AHKThread("
(
#Include <testFolder\testTwo>
)", &CritObj "", "threadName_2", false)
From the docs:
#Include <LibName> LibName
A library file or function name. For example, #include <lib> and #include <lib_func> would both include lib.ahk from one of the function library folders. LibName cannot contain variable references.
Try using: #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
------------------------------------------------- I'm a divider -------------------------------------------------
; Received a VarSetCapacity error as explained in latest github issue opened by myself (https://github.com/HotKeyIt/ahkdll-v2-release/issues/15)
; I am not positive that you can pass Critical Objects via BinRun
#Include <folder\defaultObject>
CritObj := CriticalObject(defaultObject)
file:=FileRead("testTwo","RAW")
PID := BinRun(&file, &CritObj "")
I don't know where the variable "defaultObject" comes from, I will assume it's declared on "folder\defaultObject".
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
Try:
; This runs the script immediately in-line, it does not care that I'm passing it to AHKThread (it never establishes a second thread)
; This also does not resolve the issue of needing to import Library files into the second thread (e.g. #Include <utils>)
#Include <testFolder\defaultObject>
CritObj := CriticalObject(defaultObject)
script :=
(
MsgBox("test")
)
thread := AHKThread(script, &CritObj "", "threadName_2", false)
I appreciate the insight, but we unfortunately haven't gotten much further. This may be due to an excess of information in my OP, so I have boiled down the information a little better:
As you can see, when it compiles, the #Include <testFolder\defaultObject> works as I desire, bringing that code into the compiled .exe.
However, the #Include <testFolder\testTwo> inside of the script variable does not bring that code into the compiled .exe, causing an error in the compiled .exe.
Error at line 1.
Line Text: #Include <testFolder\testTwo>
Error: Function library not found.
The program will exit
For reference to my end goal, I am attempting to compile as such that everything is stored in a compiled state, and none of the code remains in .ahk format. For default #Include at the top of a script file, this works wonderfully as the compiler knows to compile it inside of the script.
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
I'll keep this in mind, but there is currently a conflict with the latest v2.110 Merge that I would need to account for in order to properly try BinRun, I may revert my Custom ahkdll alpha bin to a previous commit for testing this weekend.
I appreciate the insight, but we unfortunately haven't gotten much further. This may be due to an excess of information in my OP, so I have boiled down the information a little better:
As you can see, when it compiles, the #Include <testFolder\defaultObject> works as I desire, bringing that code into the compiled .exe.
However, the #Include <testFolder\testTwo> inside of the script variable does not bring that code into the compiled .exe, causing an error in the compiled .exe.
Error at line 1.
Line Text: #Include <testFolder\testTwo>
Error: Function library not found.
The program will exit
For reference to my end goal, I am attempting to compile as such that everything is stored in a compiled state, and none of the code remains in .ahk format. For default #Include at the top of a script file, this works wonderfully as the compiler knows to compile it inside of the script.
BinRun requires you to pass the .exe's content as parameter but you are reading a file without an extension.
I'll keep this in mind, but there is currently a conflict with the latest v2.110 Merge that I would need to account for in order to properly try BinRun, I may revert my Custom ahkdll alpha bin to a previous commit for testing this weekend.
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.
About the order in the msgboxes, it's normal because without the quotes it parses it in a different way.
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.
Unfortunately, this is not what I am attempting to accomplish, I have failed to explain this twice.
If I utilize this method, the #Include continues to not house the script upon compiling. Thus requiring an AHK file to be shipped with the program which I do not want.
For example, this default object code has been working as expected this whole time, and it is inside of the Library folder.
However, as soon as you attempt one of these two methods, the Ahk2Exe Script Parser fails to Include the file as you I would expect, thus causing the error (UNLESS YOU PACKAGE THE FILE MANUALLY ALONGSIDE THE COMPILED EXECUTABLE).
The library thing that happens after compiling is because when you use #include with "<>" you are including it from one of the function library folders (predefined). You should try using #Include FULL_PATH_TO_FILE replace "FULL_PATH_TO_FILE" with the full path to the file (can be relative but it needs to contain the name and extension of the file), for example "testFolder\defaultObject.ahk"
That is exactly what you need.
Unfortunately, this is not what I am attempting to accomplish, I have failed to explain this twice.
If I utilize this method, the #Include continues to not house the script upon compiling. Thus requiring an AHK file to be shipped with the program which I do not want.
For example, this default object code has been working as expected this whole time, and it is inside of the Library folder.
However, as soon as you attempt one of these two methods, the Ahk2Exe Script Parser fails to Include the file as you I would expect, thus causing the error (UNLESS YOU PACKAGE THE FILE MANUALLY ALONGSIDE THE COMPILED EXECUTABLE).
Which leads me to believe that I need to make an update to the ScriptParser.ahk to handle this use case.
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?
Yes, this works as expected. I believe you are starting to understand the issue.
The issue appears when we try to utilize the "( #Include )" logic due to it staying a string value rather than being compiled down into the script.
E.g.
Hello, if #Include FULL_PATH_TO_FILE doesn't work then there is something wrong with the compiler.
Let's try this:
1. Make an empty ahk script called compileMe.ahk
2. Make another ahk script called includeMe.ahk with this line only: msgbox("Im included")
3. Put this in "compileMe.ahk" #Include FULL_PATH_TO_INCLUDEME.AHK ofc replace "FULL_PATH_TO_INCLUDEME.AHK" with the actual full path to includeMe.ahk.
4. Compile compileMe.ahk and open it.
Does it show the msgbox?
Yes, this works as expected. I believe you are starting to understand the issue.
The issue appears when we try to utilize the "( #Include )" logic due to it staying a string value rather than being compiled down into the script.
E.g.
Unfortunately, this does not accomplish what is necessary either due to the includeMe.ahk file needing to contain #Includes as well, but that is something I thought about.
The true workaround is to make the includeMe.ahk file be completely #Include-less, but that would introduce a ton of bloat to my program. This is why I was looking to validate if I was doing this correctly.
; includeMe.ahk
; This causes utils to be loaded inside of the location of #Include Lib\includeMe.ahk rather than inside of the AhkThread()
#Include <utils>
script := "
(
msgbox("Im included")
utilityFunc()
)"