What do I have to do to make my WH_SHELL or WH_CBT hook procedure receive events from other processes?

前端 未结 5 870
悲哀的现实
悲哀的现实 2020-12-09 19:24

I\'m trying to use SetWindowsHookEx to set up a WH_SHELL hook to get notified of system-wide HSHELL_WINDOWCREATED and HSHELL_WIN

5条回答
  •  隐瞒了意图╮
    2020-12-09 20:11

    I found the Delphi base documentation for SetWindowsHookEx. But the text is a bit vague.

    function SetWindowsHookEx(idHook: Integer; lpfn: TFNHookProc; 
      hmod: HInst; dwThreadId: DWORD): HHOOK;
    
    • hmod: A handle to the module (a DLL) containing the hook function pointed to by the lpfn parameter. This parameter must be set to zero if dwThreadId identifies a thread created by the current process an dlpfn points to a hook function located in the code associated with the current process.

    • dwThreadId: The identifier of the thread to which the installed hook function will be associated. If this parameter is set to zero, the hook will be a system-wide hook that is associated with all existing threads.

    By the way, for the hmod parameter you should have used a module handle. (HINSTANCE points to the application handle).

    hand := GetModuleHandle('hookhelper.dll');
    Hook := SetWindowsHookEx(WH_SHELL, @HookProc, hand, 0);
    

    But although hand differs from HINSTANCE it still shows the same result.

提交回复
热议问题