c++ - C++ 脚本无法从 AHK 检索变量
问题描述
我正在尝试制作一个运行 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"
解决方案
推荐阅读
- python - 如何找到函数的所有极值点(最小值和最大值)
- javascript - 如何编写递归javascript函数以实现所需的输出
- ios - ios 13 以下版本的 info.plist 中的 DarkMode UIUserInterfaceStyle 键
- javascript - 快速会话:“会话和部分”类型上不存在属性“登录”
'。(2339) - python - 使用 pandas 数据框更快地替代 np.where?
- ios - 如何解决 NSScanner 上的“架构 x86_64 的未定义符号”?react-native 中的 Swift pod
- reactjs - 数据获取和清理以在 apexcharts 中创建图表
- r - 在 plotly 中更改悬停时的条形颜色
- r - R - fasttext 如何从命令行将输出加载到数据框中
- dictionary - 在golang中访问映射指针中的对象,取消引用会导致映射副本吗?