SetWindowsHookEx (Compact 7)

3/12/2014

Installs an application-defined hook procedure. You would install a hook procedure to monitor the system for certain types of events.

Syntax

HHOOK WINAPI SetWindowsHookEx(
  _In_  int idHook,
  _In_  HOOKPROC lpfn,
  _In_  HINSTANCE hMod,
  _In_  DWORD dwThreadId
);

Parameters

  • idHook [in]
    The type of hook procedure to be installed. This parameter can be only one of the following values in a single call.

    Value Description

    WH_KEYBOARD_LL

    Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc callback function.

    WH_MOUSE_LL

    Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc callback function.

  • lpfn
    [in] A pointer to the hook procedure. lpfn can only point to a hook procedure in the code associated with the current process.
  • hMod
    [in] Not used.
  • dwThreadId
    [in] Not supported; must be NULL.

Return Value

If the function succeeds, the return value is non-NULL handle but it is not a handle to the next Hook function in a chain. If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

An error may occur if the dwThreadId parameter is not NULL.

HOOKPROCs are called in the context of the internal Message Queue architecture. In this context further processing by the message queue for the system is blocked until your application returns from HOOKPROC.

Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook.

The scope of hooks are system wide and not restricted to your specific application.

Hook Scope

WH_KEYBOARD_LL

System wide

WH_MOUSE_LL

System wide

Successive calls to SetWindowsHookEx will fail after the first successful call. The Win32 version of CallNextHookEx is not supported and not required since a HOOK in this case is specific to the application. If you use a hook in a secondary thread, there must be a message pump associated with the secondary thread.

See Also

Reference

Window Functions