What does Windows error code 1428 (ERROR_HOOK_NEEDS_HMOD) mean?

 
Previous Next
ERROR_INVALID_FILTER_PROC ERROR_GLOBAL_ONLY_HOOK

ERROR_HOOK_NEEDS_HMOD

The hook scope requires a module handle

For SetWindowsHookEx, callback placement depends on the target thread and process. If the hook is associated with all threads in a desktop or with a thread created by another process, the callback must be in a DLL and hmod identifies that DLL.

Using NULL for hmod is valid only for the documented same-process case where the hook procedure is in the current process code. Expanding a previously thread-local hook to global scope without changing packaging commonly exposes this error.

What to check

  • Compare dwThreadId with the process that owns the target thread.
  • For global/cross-process hooks, place the callback in a DLL and pass its module handle.
  • Keep 32-bit and 64-bit hook DLL requirements in mind on 64-bit Windows.
  • Do not substitute the application instance handle if it does not contain the callback code.

The callback itself may be valid; the failure is that USER32 cannot associate nonlocal hook code with the required containing module.

References


Looking for a different code? Search another status or error code.