开发者

calling setwindowshookex with WH_GETMESSAGE doesn't work on any process except the injector

I previously asked a question about something similar but I believe this time the circumstances are different.

I have a DLL that has standard hook, unhook and msgProc functions. I load this DLL in my main application and then call 'hook', that is below:

HOOKDLL_API BOOL setHook( HWND hWnd, DWORD threadID )
{

if( hWndServer != NULL )
    return FALSE;

hook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)msghook, hInstance, threadID );

if( hook != NULL )
{
    hWndServer = hWnd;

    ofstream logFile;
    logFile.open( "LOG.txt" );
    logFile << "Hooked for: " << hWndServer << endl;
    logFile.close();

    return TRUE;
}

return FALSE;
}

The problem is that if I make it global, with threadID = 0, then msg开发者_运维知识库Hook only and only captures the messages received by the window of the process that loaded the library and nothing else, even if it is supposed to be a global hook.

If I supply a threadID of some other window, then I don't receive messages at all.

What could perhaps be the reason for it?


  • Are you using 64-bit Windows? If so, your hook process and DLL must match the bitness of the process(es) you wish to hook.

  • What is hInstance in your example? The DLL or the EXE instance? It should be the DLL that contains the msgHook function.

  • What does your msgHook do? How do you detect whether or not it is being called? Note that it will be called within the process(es) that you hook, not within your own process. (So if you've set a breakpoint on it, it won't be triggered unless you attach the debugger to the process you've hooked, rather than the process that installed the hook.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜