private static void ForceUnsunscribeFromGlobalMouseEvents() { if (s_MouseHookHandle != 0) { //uninstall hook int result = ImportFunctions.UnhookWindowsHookEx(s_MouseHookHandle); //reset invalid handle s_MouseHookHandle = 0; //Free up for GC s_MouseDelegate = null; //if failed and exception must be thrown if (result == 0) { //Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. int errorCode = Marshal.GetLastWin32Error(); //Initializes and throws a new instance of the Win32Exception class with the specified error. throw new Win32Exception(errorCode); } } }
/// <summary> /// Uninstalls the global hook /// </summary> public void unhook() { ImportFunctions.UnhookWindowsHookEx(hhook); }