I need to detect end of script execution and read two varables but ahkgetvar returns very strange values.
Here is my test script:
ScriptResultName:="TestValue" ScriptResultValue:=100 Loop, 5 { SoundBeep, 1500, 200 ScriptResultValue:=ScriptResultValue + 1 Sleep 500 } ScriptReady:=1 Sleep 100
DWORD WINAPI AHKEngineThread() { const HINSTANCE hAutoHotkeyDLL = LoadLibrary(m_AHKEngineDLLFileName); if (!hAutoHotkeyDLL) { DebugLog(_T("AHKEngineThread::Failed to load Autohotkey engine!")); AfxEndThread(0); return 0; } const FuncPtr_ahkdll AutoHotkeyRunScriptFromFile = (FuncPtr_ahkdll)GetProcAddress(hAutoHotkeyDLL, "ahkdll"); const FuncPtr_ahktextdll AutoHotkeyRunScriptFromString = (FuncPtr_ahktextdll)GetProcAddress(hAutoHotkeyDLL, "ahktextdll"); const FuncPtr_ahkReady AutoHotkeyIsScriptRunning = (FuncPtr_ahkReady)GetProcAddress(hAutoHotkeyDLL, "ahkReady"); const FuncPtr_ahkassign AutoHotkeySetVariable = (FuncPtr_ahkassign)GetProcAddress(hAutoHotkeyDLL, "ahkassign"); const FuncPtr_ahkgetvar AutoHotkeyGetVariable = (FuncPtr_ahkgetvar)GetProcAddress(hAutoHotkeyDLL, "ahkgetvar"); AutoHotkeyRunScriptFromFile(AHKEngineScriptFilePath, NULL, NULL); bool ReadValue = true; while (AutoHotkeyIsScriptRunning()) { Sleep(25); LPCTSTR ScriptReady = AutoHotkeyGetVariable(_T("ScriptReady"), FALSE); if ((ReadValue) && (ScriptReady != NULL)) { if (_tcscmp(ScriptReady, _T("1")) == 0) { LPCTSTR ScriptResultName = AutoHotkeyGetVariable(_T("ScriptResultName"), FALSE); LPCTSTR ScriptResultValue = AutoHotkeyGetVariable(_T("ScriptResultValue"), FALSE); if ((ScriptResultName != NULL) && (ScriptResultValue != NULL)) { DebugLog(_T("Script result: Name: %s Value: %s"), ScriptResultName, ScriptResultValue); } ReadValue = false; } } } FreeLibrary(hAutoHotkeyDLL); AfxEndThread(0); return 0; }
if ScriptResultValue is read before ScriptResultName result is:
Script result: Name: TestValue Value: TestValue
So I am really confused. What is thу right way to read integer and string values from script engine?