Reputation: 812
I am using a windows hook in my application to determine whether another application has been re-sized. I then take some action depending on the new size of the other application.
This works fine in pure 32 bit environment and pure 64 bit environment (hook dll complied as 64 bit and 32 bit separately as in the MSDN docs).
However here is the problem. Because of a mix of 32bit and 64bit application in say Window 64bit OS, if I launch the 64bit version of my application, I cannot monitor 32bit applications and vice versa.
Is there any good way to do this. It can be a completely different mechanism.
Upvotes: 1
Views: 1835
Reputation: 24447
Unfortunately, you are only able to inject 32-bit DLLs to a 32-bit processes and a 64-bit DLLs to 64-bit processes. This means you will need 2 versions of your DLL. On top of this, SetWindowsHookEx() must be invoked from the same family of portable executable (that is, it will have to be invoked from 32-bit code for 32-bit processes and similarly for 64-bit processes).
Given your application is 64-bit, you'll have to launch an instance of your 32-bit program and have it set the hook. You would probably want to have one of these as a child
which notifies the parent
when the event you are interested in has been trapped.
From the docs:
SetWindowsHookEx can be used to inject a DLL into another process. A 32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL cannot be injected into a 32-bit process. If an application requires the use of hooks in other processes, it is required that a 32-bit application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit processes, and a 64-bit application call SetWindowsHookEx to inject a 64-bit DLL into 64-bit processes. The 32-bit and 64-bit DLLs must have different names.
Upvotes: 1