Discussion:
SetWindowsHookEx and WH_MOUSE behavior in W7 64-Bit
(too old to reply)
mac10
2010-06-07 14:02:24 UTC
Permalink
I successfully use

SetWindowsHookEx(WH_MOUSE,MouseProc_,0,GetCurrentThreadId());

to set a hook for mouse messages in my application.

In the handler function I react on the WM_MOUSEWHEEL message and work with
the mouseData member to determine the wheel delta etc.
...
MOUSEHOOKSTRUCTEX* pdata = (MOUSEHOOKSTRUCTEX*)lParam;
if (wParam == WM_MOUSEWHEEL) {
WORD h = HIWORD(pdata->mouseData);
WORD l = LOWORD(pdata->mouseData);
}
...

My application is 32 Bit.

This code works flawlessy under 32-Bit Windows versions, but fails under
Windows 7 64-Bit.

The data in the pdata->mouseData member appears to be rubbish, it contains
no valid wheel delta values or flags at all.

This looks like a bug in Windows to me, most likely in the WoW64 which
marshalls the hook from 64 to 32 bit..

Any ideas how to get this working or fixed?
Tim Roberts
2010-06-08 05:59:47 UTC
Permalink
Post by mac10
I successfully use
SetWindowsHookEx(WH_MOUSE,MouseProc_,0,GetCurrentThreadId());
to set a hook for mouse messages in my application.
In the handler function I react on the WM_MOUSEWHEEL message and work with
the mouseData member to determine the wheel delta etc.
...
My application is 32 Bit.
This code works flawlessy under 32-Bit Windows versions, but fails under
Windows 7 64-Bit.
The data in the pdata->mouseData member appears to be rubbish, it contains
no valid wheel delta values or flags at all.
This looks like a bug in Windows to me, most likely in the WoW64 which
marshalls the hook from 64 to 32 bit..
There is no marshalling. Check the documentation. You can't insert a
32-bit hook into a 64-bit process, nor can you insert a 64-bit hook into a
32-bit process. If you want to capture both, then you need to create a
32-bit DLL and a 64-bit DLL, and they have to have different DLL names.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Richard Russell
2010-06-08 14:53:30 UTC
Permalink
There is no marshalling.  Check the documentation.  You can't insert a
32-bit hook into a 64-bit process, nor can you insert a 64-bit hook into a
32-bit process.  If you want to capture both, then you need to create a
32-bit DLL and a 64-bit DLL, and they have to have different DLL names.
The OP appears to be installing his hook only for the current thread;
therefore it's not a global hook and doesn't need to be in a DLL. I
can't see anything in the documentation that suggests a local 32-bit
hook, with its procedure in the same module as the calling
application, won't work correctly under WoW64.

Richard.
http://www.rtrussell.co.uk/

Loading...