问题描述
usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Runtime.InteropServices;usingSystem.IO;usingSystem.Windows.Forms;namespace钩子练习2{classProgram{[DllImport("user32.dll")]publicstaticexternintSetWindowsHookEx(intidHook,HookProclpfn,IntPtrhInstance,intthreadId);[DllImport("user32.dll")]staticexternshortGetKeyState();[DllImport("kernel32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]publicstaticexternIntPtrGetModuleHandle(stringlpModuleName);publicdelegateintHookProc(intnCode,Int32wParam,IntPtrlParam);staticvoidMain(string[]args){HookProcKeyboardHookDelegate=newHookProc(KeyboardHookProc);intmhHook=SetWindowsHookEx(13,KeyboardHookDelegate,GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName),0);Console.WriteLine(mhHook);MessageBox.Show("钩到了吗?");Console.ReadKey();}staticintKeyboardHookProc(intnCode,Int32wParam,IntPtrlParam){if(nCode>0){MessageBox.Show("我钩到了。");}return1;}}}
解决方案
解决方案二:
看程序是不是32位的
解决方案三:
引用1楼wq1234wq的回复:
看程序是不是32位的
我的是xp系统。