c#全局钩子的问题,老是返回0,谁帮忙,谢谢
SetWindowsHookEx(this.type,proc,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly()....
SetWindowsHookEx(this.type,proc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
展开
2013-07-14
展开全部
申明这个方法前必须先实例化钩子 安装 再申明方法。 /// <summary>
/// 键盘钩子句柄
/// </summary>
private IntPtr m_pKeyboardHook = IntPtr.Zero; /// <summary>
/// 钩子委托声明
/// </summary>
/// <param name="nCode"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); /// <summary>
/// 键盘钩子委托实例
/// </summary>
/// <remarks>
/// 不要试图省略此变量,否则将会导致
/// 激活 CallbackOnCollectedDelegate 托管调试助手 (MDA)。
/// 详细请参见MSDN中关于 CallbackOnCollectedDelegate 的描述
/// </remarks>
private HookProc m_KeyboardHookProcedure; // 底层键盘钩子
public const int idHook = 13; /// <summary>
/// 安装钩子
/// </summary>
/// <param name="idHook"></param>
/// <param name="lpfn"></param>
/// <param name="hInstance"></param>
/// <param name="threadId"></param>
/// <returns></returns>
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr pInstance, int threadId);
/// 键盘钩子句柄
/// </summary>
private IntPtr m_pKeyboardHook = IntPtr.Zero; /// <summary>
/// 钩子委托声明
/// </summary>
/// <param name="nCode"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); /// <summary>
/// 键盘钩子委托实例
/// </summary>
/// <remarks>
/// 不要试图省略此变量,否则将会导致
/// 激活 CallbackOnCollectedDelegate 托管调试助手 (MDA)。
/// 详细请参见MSDN中关于 CallbackOnCollectedDelegate 的描述
/// </remarks>
private HookProc m_KeyboardHookProcedure; // 底层键盘钩子
public const int idHook = 13; /// <summary>
/// 安装钩子
/// </summary>
/// <param name="idHook"></param>
/// <param name="lpfn"></param>
/// <param name="hInstance"></param>
/// <param name="threadId"></param>
/// <returns></returns>
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr pInstance, int threadId);
2013-07-14
展开全部
不懂,你们学C#,你学WINDOWS程序设计吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询