views:

516

answers:

2

I have this global mouse hook setup in a DLL that watches for mouse gestures.

Everything works perfectly but with a hook set for WH_MOUSE_LL which is a low-level hook and one that doesn't need to be in an external injectable DLL.

Once I switch - to the more suitable one would say - WH_MOUSE mouse hook, everything falls apart. Once I click outside my main application (the one that installs the hook), the hook gets corrupted - ::UnhookWindowsHookEx will fail.

I only found this guy saying at experts exchange:

"No way, at least under Windows XP + SVP2 WH_MOUSE won't go global, you must use WH_MOUSE_LL instead."

I setup the hooks correctly: in a DLL using a shared data section, posting and not sending messages from the hook proceduce.

Why has this changed? And why is not documented? Anyone encountered this? Thanks!

BTW: I've reverse engineered a bit the popular StrokeIt application and it uses a combination of WH_GETMESSAGE and WH_MOUSE hooks and still works on XP/Vista...

A: 

it's news to me that a global WH_MOUSE hook is no longer supported, since i have a few apps that use it and they continue to work on XP, Vista, and Windows 7.

how are you setting up the hook? you should be able to do SetWindowsHookEx(WH_MOUSE, my_mouse_callback, g_hinstance, NULL).

the only thing i can think of is that the callback function is taking too long, in which case Windows might remove the hook, or it isn't properly calling CallNextHookEx.

~jewels

Jewel S
A: 

Not sure if this would go better as a comment, but here goes: I believe according to MSDN WH_MOUSE is supported at thread level or global.

As you pointed out yourself there are a bunch of apps using it.

So my guess is your specific implementation of the global WH_MOUSE has an issue that needs to be debugged and fixed. When you say that "the hook gets corrupted", what exactly happens? Does the hooked app crash? Could you attach a debugger to the app that you expect mouse events from and check what really crashes in your hook?

Dan Cristoloveanu