UnhookWindowsHookEx function
Applies to: desktop apps only
Removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.
Syntax
BOOL WINAPI UnhookWindowsHookEx( __in HHOOK hhk );
Parameters
- hhk [in]
-
Type: HHOOK
A handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
Return value
Type:
Type: BOOL
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The hook procedure can be in the state of being called by another thread even after UnhookWindowsHookEx returns. If the hook procedure is not being called concurrently, the hook procedure is removed immediately before UnhookWindowsHookEx returns.
Examples
For an example, see Monitoring System Events.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- SetWindowsHookEx
- Conceptual
- Hooks
Send comments about this topic to Microsoft
Build date: 2/3/2012
Found a good description of why hooks do not attach and detach immediately after SetWindowsHookEx and UnhookWindowsHookEx:
"After a successful call to SetWindowsHookEx, the system maps the DLL into the address space of the hooked thread automatically, but not necessary immediately. Because windows hooks are all about messages, the DLL isn't really mapped until an adequate event happens. The same is true for unmapping the DLL after calling UnhookWindowsHookEx. The DLL isn't really unmapped until an adequate event happens" by Robert Kuster
This article helped me a lot — http://www.codeproject.com/KB/threads/winspy.aspx?display=Print
- 12/30/2011
- Inversion_
- 12/30/2011
- Inversion_
- 1/14/2011
- manuell
[DllImport("user32.dll")]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
- 12/9/2009
- Philipp Schwesig
- 12/9/2009
- Philipp Schwesig