Solved

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

Posted on 2008-10-28
2
1,166 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

775 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