SetWindowsHookEx - LowLevelMouseProc
-
Hallo,
hat jemand Erfahrungen mit der LowLevelMouseProc Callback Funktion gemacht? Bei mir passiert folgendes:
Nachdem ich den Hook (erfolgreich) gesetzt habe, hakt die Maus ca. 10 Sekunden und danach stürtzt das Programm ab. Der Code sieht wie unten aufgeführt aus.
Den RegistryKey "HKEY_CURRENT_USER\ControlPanel\Desktop\LowLevelHooksTimeout" habe ich auf 15 (ms) gesetzt.
// LOWLEVELMI.dll LOWLEVELMI_API LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) { if( nCode == HC_ACTION ) { MSLLData = *(reinterpret_cast<MSLLHOOKSTRUCT*>( lParam )); switch( wParam ) { case WM_LBUTTONDOWN: { *(reinterpret_cast<PULONGLONG>(&MSFrame)) = (static_cast<ULONGLONG>(MSLLData.pt.x) << 32) + MSLLData.pt.y; MSStat = MSStat | bFlagDown; } break; case WM_LBUTTONUP: { *(reinterpret_cast<PULONGLONG>(reinterpret_cast<PBYTE>(&MSFrame) + 8)) = (static_cast<ULONGLONG>(MSLLData.pt.x) << 32) + MSLLData.pt.y; MSStat = MSStat | bFlagUp; } break; } } return CallNextHookEx(NULL, nCode, wParam, lParam); }// CPP-File MSFRAME MSFrame = {0}; LPCSTR lpDLLPath = "..\\LowLevelMI\\Release\\LowLevelMI.dll"; HMODULE hDLL = LoadLibrary(lpDLLPath); if( hDLL != NULL ) { typedef LRESULT (*LPLOWLEVELMOUSEPROC)(int, WPARAM, LPARAM); typedef MSFRAME (*LPGETMOUSEINPUT) (void); LPGETMOUSEINPUT lpGetMouseInput = reinterpret_cast<LPGETMOUSEINPUT>(GetProcAddress(hDLL, "GetMouseInput")); HHOOK miHook = SetWindowsHookEx( WH_MOUSE_LL, reinterpret_cast<HOOKPROC>(GetProcAddress(hDLL, "LowLevelMouseProc")), hDLL, 0 ); if( miHook != NULL ) { lpGetMouseInput(); } else { CHAR szError[50] = {0}; sprintf_s<50>( szError, "unable to set windows hook: %d", GetLastError() ); throw std::exception(szError); } UnhookWindowsHookEx(miHook); FreeLibrary(hDLL); } else throw std::exception("LowLevelMI.dll was not found"); return MSFrame;
-
Okay hat sich erledigt. Es fehlt ein message loop im startenden thread. Stand zugegebener maßen auch bei MSDN, aber ich hatte das zunächst anders interpretiert.