User32SetWindowsHookEx Method

Installs an application-defined hook procedure into a hook chain.

You would install a hook procedure to monitor the system for certain types of events.

These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("User32.dll", SetLastError = true)]
public static IntPtr SetWindowsHookEx(
	HookType hookType,
	DelegatesHookProc hookProc,
	IntPtr hInstance,
	uint threadId
)

Parameters

hookType  HookType
The type of hook procedure to be installed.
hookProc  DelegatesHookProc
A pointer to the hook procedure.

If the threadId parameter is zero or specifies the identifier of a thread created by a different process, the HookProc parameter must point to a hook procedure in a DLL. Otherwise, HookProc can point to a hook procedure in the code associated with the current process.

hInstance  IntPtr
A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.

The hInstance parameter must be set to Zero if the threadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.

threadId  UInt32
The identifier of the thread with which the hook procedure is to be associated.

For desktop apps, if this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.

Return Value

IntPtr
If the function succeeds, the return value is the handle to the hook procedure.

If the function fails, the return value is Zero.

To get extended error information, call GetLastWin32Error.

Remarks

See Also