Ejemplo n.º 1
0
        /// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            /// Error check
            if (Handle != 0)
            {
                throw new Exception("Hook is already installed");
            }

            #region htype
            int htype = 0;

            switch (HookType)
            {
            case HookTypes.Mouse:
                htype = WinApi.WH_MOUSE_LL;
                break;

            case HookTypes.Keyboard:
                htype = WinApi.WH_KEYBOARD_LL;
                break;

            default:
                throw new Exception("HookType is not supported");
            }
            #endregion

            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);

            /// Hook
            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);

            /// Error check
            // if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
        }
Ejemplo n.º 2
0
        private void InstallHook()
        {
            if (_handle != IntPtr.Zero)
            {
                throw new InvalidOperationException("Hook is already installed");
            }

            int htype = 0;

            switch (_hookType)
            {
            case HookTypes.Mouse:
                htype = HookIds.WH_MOUSE_LL;
                break;

            case HookTypes.Keyboard:
                htype = HookIds.WH_KEYBOARD_LL;
                break;

            default:
                throw new ArgumentException("HookType is not supported");
            }

            _HookProc = HookProc;
            _handle   = NativeMethods.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
            //_handle = NativeMethods.SetWindowsHookEx(htype, _HookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);

            int lastWin32Error = Marshal.GetLastWin32Error();

            if (_handle == IntPtr.Zero)
            {
                throw new Win32Exception(lastWin32Error);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            if (!WinApi.IsWindows)
            {
                return;
            }

            /// Error check
            if (Handle != 0)
            {
                throw new Exception("Hook is already installed");
            }

            #region htype
            int htype = 0;

            switch (HookType)
            {
            case HookTypes.Mouse:
                htype = WinApi.WH_MOUSE_LL;
                break;

            case HookTypes.Keyboard:
                htype = WinApi.WH_KEYBOARD_LL;
                break;

            default:
                throw new Exception("HookType is not supported");
            }
            #endregion

            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);

            /// Hook
            /// Ed Obeda suggestion for .net 4.0
            //_hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, System.Diagnostics.Process.GetCurrentProcess().MainModule.BaseAddress, 0);

            /// Error check
            if (Handle == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 4
0
        private void InstallHook()
        {
            // Error check
            if (_handle != IntPtr.Zero)
            {
                throw new Exception("Hook is already installed");
            }

            #region htype
            int htype = 0;

            switch (_hookType)
            {
            case HookTypes.Mouse:
                htype = WinApi.WH_MOUSE_LL;
                break;

            case HookTypes.Keyboard:
                htype = WinApi.WH_KEYBOARD_LL;
                break;

            default:
                throw new Exception("HookType is not supported");
            }
            #endregion

            // Delegate to recieve message
            _HookProc = HookProc;

            // Hook
            // Ed Obeda suggestion for .net 4.0
            //_hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
            _handle = WinApi.SetWindowsHookEx(htype, _HookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);
            int lastWin32Error = Marshal.GetLastWin32Error();
            // Error check
            if (_handle == IntPtr.Zero)
            {
                throw new Win32Exception(lastWin32Error);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            /// Error check
            if (Handle != 0)
            {
                throw new Exception("Hook is already installed");
            }

            #region htype
            int htype = 0;

            switch (HookType)
            {
            case HookTypes.Mouse:
                htype = WinApi.WH_MOUSE_LL;
                break;

            case HookTypes.Keyboard:
                htype = WinApi.WH_KEYBOARD_LL;
                break;

            default:
                throw new Exception("HookType is not supported");
            }
            #endregion

            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);

            /// Hook
            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Diagnostics.Process.GetCurrentProcess().MainModule.BaseAddress, 0);

            /// Error check
            if (Handle == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            /// Error check
            if (Handle != 0) throw new Exception("Hook is already installed");

            #region htype
            int htype = 0;

            switch (HookType)
            {
                case HookTypes.Mouse:
                    htype = WinApi.WH_MOUSE_LL;
                    break;
                case HookTypes.Keyboard:
                    htype = WinApi.WH_KEYBOARD_LL;
                    break;
                default:
                    throw new Exception("HookType is not supported");
            }
            #endregion

            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);

            /// Hook
            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);

            /// Error check
            if (Handle == 0)
            {
                //throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Installs the actual unsafe hook
        /// </summary>
        private void InstallHook()
        {
            /// Error check
            if (Handle != 0) throw new Exception("Hook is already installed");

            #region htype
            int htype = 0;

            switch (HookType)
            {
                case HookTypes.Mouse:
                    htype = WinApi.WH_MOUSE_LL;
                    break;
                case HookTypes.Keyboard:
                    htype = WinApi.WH_KEYBOARD_LL;
                    break;
                default:
                    throw new Exception("HookType is not supported");
            }
            #endregion

            /// Delegate to recieve message
            _HookProc = new HookProcCallBack(HookProc);

            /// Hook
            _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, System.Diagnostics.Process.GetCurrentProcess().MainModule.BaseAddress, 0);

            /// Error check
            if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
        }