Click to See Complete Forum and Search --> : WH_KEYBOARD hook, DLL mapping


slapout
June 14th, 2005, 03:37 PM
I'm installing a WH_KEYBOARD hook on a certain application in order to add features to it. (It's a thread specific hook.) I've got my hook procedure in a DLL and another program that sets the hook. This program runs in the background and checks every so often to see if the hook is installed, if not, it installs it. (This way, if I exit the application I'm hooking and reenter it, my features will still be there.) It works except for a couple of things. Right now, I'm using EnumProcessModules to see if my DLL has been mapped into the application's address space. The problem is, since it's a WH_KEYBOARD hook, the DLL doesn't get mapped in until a key is pressed. So, if I don't press a key when I start the application, my program keeps setting more hooks.

I've tried sending the application keypresses, but that didn't seem to work. Is there a better way to see if a DLL is mapped into a process's address space or is about to be mapped?

golanshahar
June 15th, 2005, 02:31 AM
you can use the ::GetModuleHandle(..) api to see if dll is already mapped!

if i helped dont forget to rate :-)
Cheers

slapout
June 16th, 2005, 02:19 PM
Thanks. That sounds like a good idea, but I checked and GetModuleHandle only works for callers that are in the same address space. However, I have solved my problem. I'm storing the application's window handle and checking every so often to see if it has changed. If it has, I release the hook and set a new one. (Of course, if the application isn't running, I just release the hook if I have one.)