我試圖攔截髮送到另一個進程中運行的窗口的消息,以便我可以對其中的一些進行響應。SetWindowsHookEx無法注入
注入應用程序是一個x86 WPF應用程序,通過p/invoke調用此方法。我將句柄傳遞給另一個x86進程中的窗口。
extern "C" BOOL INJ_API ::InterceptMessages(HWND hWnd)
{
if (!WM_MY_INJECT)
{
WM_MY_INJECT = RegisterWindowMessage(TEXT("WM_MY_INJECT"));
}
// Get the ID of the thread running the window.
DWORD ThreadId = GetWindowThreadProcessId(hWnd, NULL);
// Set the hook
hhk = SetWindowsHookEx(WH_GETMESSAGE, HookProc, hinstDLL, ThreadId);
// hhk is non-zero, so the hook is set up
// This will block until the WM_MY_INJECT message is processed, the hook is unhooked, and we are done injecting the application.
LRESULT result = SendMessage(hWnd, WM_MY_INJECT, NULL, NULL);
return TRUE;
}
我知道郵件正在發送,因爲結果是正確的值。但是DLL永遠不會被其他進程加載,並且在我的鉤子攔截它的情況下調用該消息。
您確定您有權注入? – hbprotoss
我在沒有UAC的情況下運行64位Windows 7 ...這兩個應用程序都由同一臺桌面上的同一個用戶運行,據我所知,我應該有權限。 –