public void Uninstall() { if (!IsInstalled) { return; } _handle.Dispose(); _handle = null; _pinnedDelegate.Free(); }
/// <inheritdoc/> /// <exception cref="Win32Exception"/> public void Install() { if (IsInstalled) { return; } // prevent managed callback from being garbage collected _pinnedDelegate = GCHandle.Alloc(Callback); _handle = new SafeHookHandle( SetWindowsHookEx(Type, Callback, IntPtr.Zero, 0)); if (_handle.IsInvalid) { throw new Win32Exception("SetWindowsHookEx error: " + Marshal.GetLastWin32Error()); } }