Exemplo n.º 1
0
 protected override bool ReleaseHandle()
 {
     //NOTE Calling Unhook during processexit causes deley
     if (_closing)
     {
         return(true);
     }
     return(HookNativeMethods.UnhookWindowsHookEx(handle) != 0);
 }
Exemplo n.º 2
0
        private static HookResult HookGlobal(int hookId, Callback callback)
        {
            HookProcedure hookProcedure = (code, param, lParam) => HookProcedure(code, param, lParam, callback);

            var hookHandle = HookNativeMethods.SetWindowsHookEx(
                hookId,
                hookProcedure,
                Process.GetCurrentProcess().MainModule.BaseAddress,
                0);

            if (hookHandle.IsInvalid)
            {
                ThrowLastUnmanagedErrorAsException();
            }

            return(new HookResult(hookHandle, hookProcedure));
        }
Exemplo n.º 3
0
        private static HookResult HookApp(int hookId, Callback callback)
        {
            HookProcedure hookProcedure = (code, param, lParam) => HookProcedure(code, param, lParam, callback);

            var hookHandle = HookNativeMethods.SetWindowsHookEx(
                hookId,
                hookProcedure,
                IntPtr.Zero,
                ThreadNativeMethods.GetCurrentThreadId());

            if (hookHandle.IsInvalid)
            {
                ThrowLastUnmanagedErrorAsException();
            }

            return(new HookResult(hookHandle, hookProcedure));
        }
Exemplo n.º 4
0
 private static IntPtr CallNextHookEx(int nCode, IntPtr wParam, IntPtr lParam)
 {
     return(HookNativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
 }