C#系统钩子的实现

作者在 2009-12-20 17:36:32 发布以下内容
C#的系统钩子要点
1.载入钩子函数
  [DllImport("user32.dll", CharSet = CharSet.Auto,
            CallingConvention = CallingConvention.StdCall)]
        private static extern int CallNextHookEx(
            int idHook,
            int nCode,
            int wParam,
            IntPtr lParam);
        [DllImport("user32.dll", CharSet = CharSet.Auto,
            CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        private static extern int SetWindowsHookEx(
            int idHook,
            HookProc lpfn,
            IntPtr hInstance,
            int threadId);
        [DllImport("user32.dll", CharSet = CharSet.Auto,
            CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        private static extern int UnhookWindowsHookEx(int idHook);
//f上面三个分别是SetWindowsHookEx()建立钩子
//UnhookWindowsHookEx()撤销钩子
//CallNextHookEx()回叫函数
呵呵
2。全局实现
SetWindowsHookEx(
                    WH_MOUSE_LL,
                    s_MouseDelegate,
                    Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),//重点
                    0);
注意包含System.Reflection;
 
3.CallNextHookEx()就是自己的喜好了。嗯就这样
纯技术 | 阅读 1770 次
文章评论,共0条
游客请输入验证码
浏览260731次