|
-
December 23rd, 2006, 08:42 AM
#1
Can't set windows hook - what wrong with my code ?
Hi All,
I need to catch all keyboard event and some of the keyboard keys i need to intercept.
So i using windows hook to do it.
But in some reason when i do "SetWindowsHookEx" i getting wrong return code and my hook does not working.
This is my code ( just the relevant part ):
LRESULT CALLBACK KeyboardProc(int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
LRESULT lRetCode = 0;
return lRetCode;
}
LRESULT SetHook()
{
HINSTANCE hinstance = NULL;
HHOOK hookHandle = NULL;
LRESULT lRetCode = 0;
hookHandle = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hinstance, 0);
return lRetCode;
}
What i did wronge ?
Thanks for any help.
-
December 23rd, 2006, 01:36 PM
#2
Re: Can't set windows hook - what wrong with my code ?
void main(void)
{
HMODULE hModule= LoadLibrar("yourhook.dll");
fKeyProc fp = (fKeyProc) GetProcAddress(hModule, "KeyProc");
SetWindowsHookEx(WH_KEYBOARD, fp, (HINSTANCE)hModule, 0);
}
Hope this helps.
-
December 24th, 2006, 11:14 AM
#3
Re: Can't set windows hook - what wrong with my code ?
-
December 24th, 2006, 12:15 PM
#4
Re: Can't set windows hook - what wrong with my code ?
Yes, the procedure should be in a dll. Then only, can OS map it to all the processes
-
December 24th, 2006, 01:49 PM
#5
Re: Can't set windows hook - what wrong with my code ?
 Originally Posted by YANSHOF
This is my code ( just the relevant part ):
You missed most relevant part: hook callback.
Global hook in a DLL needs shared data segment. It is most likely that you did not use it.
If you are going to use your hook only in NT family you can use low level keyboard hook that is always global and can be set with callback in n exe module.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
December 25th, 2006, 07:25 AM
#6
Re: Can't set windows hook - what wrong with my code ?
You should make the HOOK handle globaly shared in DLL's shared segment,
How To Share Data Between Different Mappings of a DLL
Regards,
Ramkrishna Pawar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|