1
votes

I get a problem when I using keyboard hook on window7 64bit. I do these things: 1. Create a 32bit dll 2. Load it to application and setWindowHookEx

I've hooked successfully on 32bit application (Y!M, Skype...) but when I hooked on my desktop or any 64bit application (notepad) that application come freezes until I stop my hook application. I create 64bit dll, do the same at above, and get the same problem with 32bit process.

So, I think the problem is in my 32bit dll, can't be injected to 64bit process. But I don't know how can I inject 64bit dll to process when window is focusing on it.

I want to know any way to do it, and how to do it. Or can I only hook on 32bit process and don't hook on 64bit process, can you show me the way to do it. Thanks.

1
You'll need to create a 64-bit app to hook 64-bit processes. So you basically need 3 processes, one for hooking 32-bit apps, one for 64-bit apps and one that coordinates them. Avoid all this by using a low-level keyboard hook, it doesn't require injecting a DLL. - Hans Passant

1 Answers

2
votes

The problem is that you cannot load a 32-bit DLL into a 64-bit process, or a 64-bit DLL into a 32-bit process. From Programming Guide for 64-bit Windows:

... 32-bit processes cannot load 64-bit DLLs for execution, and 64-bit processes cannot load 32-bit DLLs for execution.

You will need to have two versions of your DLL: 32-bit and 64-bit. But that is only a part solution. Additionally, you will need to determine the architecture of the process into which you want to load your DLL. The WINAPI function GetBinaryType() can determine that, but it takes a path to a binary which your code must acquire.