Solved

SetWindowHookEx() from 32-bit app to get events from 64-bit apps.

Posted on 2008-10-28
2
1,179 Views
Last Modified: 2013-12-04
I have a management app which calls SetWindowsHookEx(WH_CALLWNDPROC, ..., ..., 0); This is in a 32-bit DLL which is loaded from my 32-bit app. On Vista-32, it works as expected. On Vista-64, the call succeeds and I do see the events from all 32-bit apps running on the same desktop.

However, I want to be able to see ALL events on the same desktop; not just those from 32-bit apps. MSDN sheds liight:

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.

I suppose I could write a 64-bit helper app which my 32-bit app would run. That app could then load the 64-bit dll which could then hook the 64-bit apps. IPC would have to be tight, as I do not think my 32-bit app can call into a 64-bit DLL (or am I mistaken???). I was thinking of using WM_COPYDATA as the quick and simple IPC. I will be calling this often, but the return data is not very large.

Before I start down that road, is that the best way to do this? Is there some other way a 32-bit app can load a 64-bit DLL and call into it? Any ideas???? Since this app is a C++ Win32 app, any code snippets in C++ would be appreciated.

0
Comment
Question by:dddogget
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 22826546
Well, since only 64bit processes can load 64bit DLLs, that's definitely the way to go. The code itself will be identical to your 32bit DLL loading code - just that it is compiled as a 64bit executable. Actually, quite simple...
0
 
LVL 41

Assisted Solution

by:graye
graye earned 250 total points
ID: 22830769
Yes, two separate apps...   However, I don't think the WM_COPYDATA is gonna work across the 32-64 boundary.   I suspect  you'll need a more "formal" transport mechanism to marshal data between the two programs, ie Named Pipes, Sockets, etc
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question