我试图获得我的EXE hwnd所以我可以获得HWND的头衔。
我已经尝试了以下内容,但它打印为空白。 (Dll代码)
BOOL CALLBACK EnumThreadWndProc(HWND argHwnd, LPARAM lParam)
{
*(HWND *)lParam = argHwnd;
return FALSE;
}
char retbuff[1024];
memset(retbuff, 0, sizeof(char) * 1024);
HWND handle;
DWORD lThreadId = GetCurrentThreadId();
EnumThreadWindows(lThreadId, EnumThreadWndProc, (long)&handle);
GetWindowTextA(handle, retbuff, 1023);
std::string windowName(retbuff);
std::wstring stemp = s2ws(windowName); // Temporary buffer is required
LPCWSTR result = stemp.c_str();
MessageBox(0, L"aaa.", result, 0); // Use good old Message Box inside Windows Api Functions but this time with your own dll }
当我在寻找解决方案时,我发现我可以通过使用以下内容从dll获得EXE的HINSTANCE:
HINSTANCE exe = GetModuleHandle(NULL);