How to get HMODULE/HINSTANCE handle of a different application?
-
From a different application, I tried to get other application handle using "HINSTANCT hInst = GetWindowLong(hWnd, GWL_HINSTANCE);" which I am using in the function "HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInst, GetWindowThreadProcessId(hWnd, NULL));". But the handle returned by "SetWindowsHookEx()" is NULL (because of 'hInst'). Could someone help me to resolve this problem by suggesting a alternate solution for this? Thanks in Advance, Rajarajan V. Rajarajan Veerichetty. IBM Software Labs, Bangalore Mobile: +91-0-9845443206
-
From a different application, I tried to get other application handle using "HINSTANCT hInst = GetWindowLong(hWnd, GWL_HINSTANCE);" which I am using in the function "HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInst, GetWindowThreadProcessId(hWnd, NULL));". But the handle returned by "SetWindowsHookEx()" is NULL (because of 'hInst'). Could someone help me to resolve this problem by suggesting a alternate solution for this? Thanks in Advance, Rajarajan V. Rajarajan Veerichetty. IBM Software Labs, Bangalore Mobile: +91-0-9845443206
The second parameter is NOT the HINSTANCE of the appliction you want to hook, but the HINSTANCE of the dll contaning the hook procedure. so you can write a DllMain function, and store the HINSTANCE of the dll in a global viriable.when you call SetWindowsHookEx, use the global viriable as the second parameter.