windows api: system wide keyboard hook problem
-
Im trying to make a program that does system wide keyboard hook. This program consist of two parts, and those are: 1. a DLL which consist of three functions: InstallHook, HookProc (the hook procedure), and RemoveHook. 2. an EXE which will load the DLL and uses/calls all the functions what the program does is, everytime there's an input from the keyobard it will pop up a messagebox saying "whoa!". the problem is that this program only monitors keystrokes on it's own thread. when the program loses focus, it will not be able to detect keystrokes and output the "whoa!" message anymore. just my thought, i think the problem lies within my installhook function within the DLL, because im not really sure how to fill the third and fourth parameters (msdn kinda confuses me) [code] SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) HookProc, GetModuleHandle(NULL), 0); [/code] this is the full source code of the program. DLL source : http://pastebin.com/468968 Exe Source : http://pastebin.com/468969 This problem really confuses me since there are no error displayed on the compiler, and the program just looks fine without crash or anything. Thank you very much for your time and help. - Ganeshwara -- modified at 3:40 Monday 19th December, 2005
-
Im trying to make a program that does system wide keyboard hook. This program consist of two parts, and those are: 1. a DLL which consist of three functions: InstallHook, HookProc (the hook procedure), and RemoveHook. 2. an EXE which will load the DLL and uses/calls all the functions what the program does is, everytime there's an input from the keyobard it will pop up a messagebox saying "whoa!". the problem is that this program only monitors keystrokes on it's own thread. when the program loses focus, it will not be able to detect keystrokes and output the "whoa!" message anymore. just my thought, i think the problem lies within my installhook function within the DLL, because im not really sure how to fill the third and fourth parameters (msdn kinda confuses me) [code] SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) HookProc, GetModuleHandle(NULL), 0); [/code] this is the full source code of the program. DLL source : http://pastebin.com/468968 Exe Source : http://pastebin.com/468969 This problem really confuses me since there are no error displayed on the compiler, and the program just looks fine without crash or anything. Thank you very much for your time and help. - Ganeshwara -- modified at 3:40 Monday 19th December, 2005
I believe you need to pass the HMODULE for the dll, not the exe, which is what GetModuleHandle(NULL) returns. Use something like GetModuleHandle("nameofdll.dll").
-
I believe you need to pass the HMODULE for the dll, not the exe, which is what GetModuleHandle(NULL) returns. Use something like GetModuleHandle("nameofdll.dll").