Пример #1
0
        public void Uninstall()
        {
            if (!IsInstalled)
            {
                return;
            }

            _handle.Dispose();

            _handle = null;
            _pinnedDelegate.Free();
        }
Пример #2
0
        /// <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());
            }
        }