SetWindowsHookEx returns 0 when compiling for the .NET 4.0 framework in 32bit machines

后端 未结 4 910
情话喂你
情话喂你 2020-12-16 20:38

I\'m trying to set a low level windows keyboard hook to grab three keys pressed even if the application is not in focus. To do this I\'m calling SetWindowsHookEx as

4条回答
  •  温柔的废话
    2020-12-16 21:11

    From the documentation for SetWindowsHookEx

    hMod [in]
    HINSTANCE
    A handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.

    So you should be passing in IntPtr.Zero for NULL

    //install hook
      hKeyboardHook = SetWindowsHookEx(
        WH_KEYBOARD_LL,
        KeyboardHookProcedure,
        IntPtr.Zero,
        0);
    

提交回复
热议问题