Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
unhookwindowshookex (user32)

C# Signature:

/// <summary>
///     Removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.
///     <para>
///     See [ ] for more
///     information
///     </para>
/// </summary>
/// <param name="hhk">
///     C++ ( hhk [in]. Type: HHOOK )<br />A handle to the hook to be removed. This parameter is a hook
///     handle obtained by a previous call to <see cref="SetWindowsHookEx" />.
/// </param>
/// <returns>
///     C++ ( Type: BOOL )
///     <c>true</c> or nonzero if the function succeeds, <c>false</c> or zero if the function fails.
///     <para>
///     To get extended error information, call
///     <see cref="!:">GetLastError</see>
///     .
///     </para>
///     <para>The return value is the calling thread's last-error code.</para>
///     The Return Value section of the documentation for each function that sets the last-error code notes the conditions
///     under which the function sets the last-error code. Most functions that set the thread's last-error code set it when
///     they fail. However, some functions also set the last-error code when they succeed. If the function is not
///     documented to set the last-error code, the value returned by this function is simply the most recent last-error
///     code to have been set; some functions set the last-error code to 0 on success and others do not.
///     <para></para>
/// </returns>
/// <remarks>
///     <para>
///     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 <see cref="UnhookWindowsHookEx" /> returns.
///     </para>
///     <para>
///     For an example, see
///     <see cref="!:">
///         Monitoring
///         System Events
///     </see>
///     .
///     </para>
/// </remarks>
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool UnhookWindowsHookEx(IntPtr hhk);

VB.NET Signature:

<DllImport("user32.dll", SetLastError := True)> _
Public Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

VB Signature:

Public Declare Function UnhookWindowsHookEx Lib "user32" _
          (ByVal hHook As Long) As Long

User-Defined Types:




Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

The ManagedWindowsApi project ( provides a Hook class and subclasses for Journal hooks, Message hooks and Low-Level hooks.


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version