How to set global hook for WH_CALLWNDPROCRET ?

Posted by user261882 on Stack Overflow See other posts from Stack Overflow or by user261882
Published on 2010-05-27T22:20:49Z Indexed on 2010/05/27 22:21 UTC
Read the original article Hit count: 596

Filed under:
|
|
|

Hello

I want to set global hook that tracks which application is active.

In my main program I am doing the foloowing :

HMODULE mod=::GetModuleHandle(L"HookProcDll");
HHOOK rslt=(WH_CALLWNDPROCRET,MyCallWndRetProc,mod,0);

The hook procedure which is called MyCallWndRetProc exists in separate dll called HookProcDll.dll. The hook procedure is watching for WM_ACTIVATE message.

The thing is that the code stucks in the line where I am setting the hook, i.e in the line where I am calling ::SetWindowsHookEx. And then Windows gets unresponsive, my task bar disappears and I am left with empty desktop. Then I must reset the computer.

What am doing wrong, why Windows get unresponsive ? and Do I need to inject HookProcDll.dll in every process in order to set the global hook, and how can I do that ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi