public void Dispose() { if (!_hook.IsClosed) { _hook.Close(); if (_hook.IsClosed) { Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "I: CBT Hook destroyed (ID={0}). {{Medo.MessageBox}}", _hook.ToString())); } else { throw new InvalidOperationException(Resources.ExceptionCbtHookCannotBeRemoved); } } _hook.Dispose(); GC.SuppressFinalize(this); }
public CbtHook(IWin32Window owner) { _owner = owner; _cbtHookProc = new NativeMethods.CbtHookProcDelegate(CbtHookProc); _hook = NativeMethods.SetWindowsHookEx(NativeMethods.WH_CBT, _cbtHookProc, IntPtr.Zero, NativeMethods.GetCurrentThreadId()); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "I: Created CBT hook (ID={0}). {{Medo.MessageBox}}", _hook.ToString())); }