我正在尝试制作一个运行AHK线程并从中检索变量的C ++脚本。它可以成功运行AHK脚本,但似乎没有返回任何内容。
typedef UINT (*pahkdll)(LPTSTR script,LPTSTR p1,LPTSTR p2);
typedef BOOL (*pahkReady)(void);
HINSTANCE handle;
pahkdll ahkdll;
pahkReady ahkReady;
void debugAHK(){
while (!ahkReady()){
Sleep(10);
}
}
bool init(){
handle = LoadLibrary("AutoHotkey.dll");
if (!handle){ std::cout << "Could not load dynamic library!\n"; return 0;}
ahkdll = (pahkdll)GetProcAddress(handle, "ahkdll");
ahkReady = (pahkReady)GetProcAddress(handle, "ahkReady");
ahkdll("","","");
debugAHK();
return 1;
}
void check(){
ahkdll("ahk.ahk", "", "");
debugAHK();
typedef wchar_t* (*AhkGetVar)(wchar_t *, UINT);
AhkGetVar l_hAutoHotKeyGetVar = (AhkGetVar)GetProcAddress(handle, "ahkgetvar");
wchar_t* wcha = l_hAutoHotKeyGetVar(L"MyVar", 0); // 0 : content, 1 : pointer
std::wstring wcha(l_sRes);
std::cout << std::string(w.begin(), w.end());
}
当我尝试返回内容时,它不返回任何内容。当我尝试返回指针时,它只是返回一个看似随机的数字序列,其后缀为.txt或其他一些随机字符串。
AHK脚本很简单:
#Persistent
#NoTrayIcon
MyVar := "test"