/// <summary> /// 设置钩子 /// </summary> /// <param name="threadId">传入的进程id</param> private void SetHook(uint threadId) { HookHandle = new HookHandleDelegate(HookCallback); HookIntptr = SetWindowsHookEx(HookTypeInt, HookHandle, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), threadId); if (HookIntptr == IntPtr.Zero) { //hookstop(); //throw new Exception("hook安装失败"); ErrorMsg = "hook安装失败"; } }
private static extern IntPtr SetWindowsHookEx(int idHook, HookHandleDelegate lpfn, IntPtr hmod, uint dwThreadId);