Global hooks problems (WH_MOUSE_LL)

Vitaliy Margolen wine-devel at
Wed Jan 25 00:50:21 CST 2006

Trying to track down the problem with our DInput implementation I found
some interesting stuff - our global hooks don't work correctly because
hook callbacks are never called if event is generated in the different
thread. I don't think this is a revelation to number of people who knew
that before. But how do we fix it?

Her is what I dug up so far:
1. Installing global hook we setting it as WINEVENT_INCONTEXT while msdn
   and tests indicate that it qualifies as WINEVENT_OUTOFCONTEXT instead.
   Unless of course we don't want to call post_win_event in step 5 and go
   to step 6 instead.
2. All HW mouse messages start here:
   From looking at it I assume that all the HW mouse hooks should be
   handled by HOOK_CallHooks function. This is because there are no code
   related to hooks in send_message server call.
3. First thing that HOOK_CallHooks does is calling HOOK_IsHooked with
   checks only current thread for installed hooks. So this is first place
   that is wrong. Let's comment that check out for now. I think we need
   to move that check farther down, after the call to server.
4. We call start_hook_chain
   to start hook callback chain. There we call get_first_valid_hook on
   local and then global if no local hooks exist. But there again we
   check for the hook
   callback thread being local (which is again not the case for global
   hooks). This is problem #2.
5. Now we have post_win_event of but right before it we hitting an assert
   so this is not the right way?
6. Say we returned with success and back to HOOK_CallHooks that now tries
   to call MSG_SendInternalMessageTimeout. Which for some reason fails to
   deliver message to our global hook.

So my question is to anyone who knows. What is the proper way to deliver
these messages to global hooks that are in a different thread/process?

Attached is the small program to test part of this. Fixing problems (1) &
(2) made it work. But it still not enough for the game (for some reason).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hooks_test.tar.bz2
Type: application/octet-stream
Size: 2162 bytes
Desc: not available
Url :

More information about the wine-devel mailing list