PDA

View Full Version : windows hook help...


grosse
March 12th, 2002, 14:15
this is similar to that hook post earlier...
suppose i create a keyboard hook

hhk = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, NULL, ThreadId);

how do i post a message to the pogram which created this hook from the KeyboardProc ... eg. to show a window or to send the WM_QUIT msg?

KeyboardProc is a pointer to a func. which handles the hook processing. Now i tried out a PostThreadMessage() to post a msg to the thread from which i set the hook by setting a global variable to contain the thread id i reqd. but within KeyBoardProc this variable appears to contain 0. I tried out static keyword before the global variable ( type DWORD ) but no go

DakienDX
March 12th, 2002, 19:59
Hello grosse !

If you set a hook in a different thread, you need to use a DLL. But the DLL has usually two data segments. One thread specified and one shared. So if you access a variable from your main program, it can have a value, but if it's accessed from the DLL in a different thread, it uses a different data segment for this thread and the variable is probably not set. Try to define the variable you need in the shared data segment, so it's accessible from all threads using the DLL.

grosse
March 15th, 2002, 15:03
oh thanx.. will try out... MSDN is somewhat confusing!

tsehp
March 17th, 2002, 14:05
to share data, you can also use file mappings, I use them a lot between processes, even if it's not the case here