Exemple #1
0
        protected override bool ReleaseHandle()
        {
            var ret = HookNativeMethods.UnhookWindowsHookEx(handle) != 0;

            if (FunctionPointer.IsAllocated)
            {
                FunctionPointer.Free();
            }

            return(ret);
        }
Exemple #2
0
        public static HookHandle Create(HookType idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId)
        {
            var FunctionPointer = GCHandle.Alloc(lpfn);

            var ret = HookNativeMethods.SetWindowsHookEx(idHook, lpfn, hMod, dwThreadId);

            if (ret.IsInvalid)
            {
                FunctionPointer.Free();
                ThrowLastUnmanagedErrorAsException();
            }
            else
            {
                ret.FunctionPointer = FunctionPointer;
            }

            return(ret);
        }