I’m currently making a plugin for one application and since it doesn’t handle the WM_MBUTTONDOWN message I decided to hook the WNDPROC but it seems that another plugin hooks it too and handles this message (since the application loads the plugins in alphabetical order, there’s a chance that I might not hook the WNDPROC last, resulting in the other plugin handling the message first). This means I’d have to be the last one to hook the WNDPROC to be able to get to those messages.
So, are there any reliable (not relying on alphabetical order, etc.) ways of hooking a procedure last?
EDIT: the hooking is done by changing the DWL_WNDPROC property of the window to the address hook procedure using the SetWindowLong function. The original DWL_WNDPROC is then called from the hook procedure using CallWindowProc. Sorry for not making this clear!
Thanks,
Tuntuni.
Well, in your installed window proc callback you could check current window proc by
GetWindowLongPtrcall and reinstall your proc withSetWindowLongPtrif someone changed it. Of course, it’s dangerous and at least will require your window proc to be protected from reentrance (usually with static counter) to avoid infinite recursion.Also you could try to use system-wide hook installed by
SetWindowsHookExAPI function instead of window subclassing –WH_MOUSEorWH_MOUSE_LLhook instead ofWH_CALLWNDPROC. It shall be called before window procedure is called (onGetMessageor even on mouse message posting for LL hook), therefore it shall occur before anyWH_CALLWNDPROChook is called.