public static extern bool UnhookWindowsHook(HookHandle hook);
public static extern IntPtr CallNextHook(HookHandle hook, int code, IntPtr wParam, IntPtr lParam);
public void Uninstall() { lock (this) { if (!this.HookHandle.IsEmpty) { while (true) { if (!UnsafeNativeMethods.UnhookWindowsHook(this.HookHandle)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } _Handle = HookHandle.Empty; this._HookProc = null; return; } } } }
/// <summary> /// Equalses the specified hook. /// </summary> /// <param name="hook">The hook.</param> /// <returns></returns> public bool Equals(HookHandle hook) { if (this._Hook.Equals(hook._Hook)) { return true; } return false; }
public void Install() { if (!this.HookHandle.IsEmpty) { this.Uninstall(); } while (true) { lock (this) { this._Handle = UnsafeNativeMethods.SetWindowsHook(this.HookType, this._HookProc, InstanceHandle.Empty, (uint)Window.ThreadID); if (this.HookHandle.IsEmpty) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return; } } }