但程序运行一会就出现未处理的System.NullReferenceException类型的异常出现在 system.windows.forms.dll 中。其他信息: 未将对象引用设置到对象的实例。谁能给分析一下,这是什么原因?先将源码附上,请大家共同探讨。/// public class MouseHook{public MouseHook(){//// TODO: 在此处添加构造函数逻辑//}#region //********API32函数声明**************// **********************************************************************// Win32: SetWindowsHookEx()[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]private static extern IntPtr SetWindowsHookEx(HookType code,HookProc func,IntPtr hInstance,int threadID);// Win32: UnhookWindowsHookEx()[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]private static extern int UnhookWindowsHookEx(IntPtr hhook);// Win32: CallNextHookEx()[DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]private static extern int CallNextHookEx(IntPtr hhook,int nCode, int wParam, IntPtr lParam);// Win32: GetModuleHandle()[DllImport("kernel32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]private static extern IntPtr GetModuleHandle(string lpModuleName);// Win32: GetForegroundWindow()[DllImport( "user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]private static extern IntPtr GetForegroundWindow();// Win32: GetWindowThreadProcessId()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern int GetWindowThreadProcessId (IntPtr hwnd,int lpdwProcessId);// Win32: GetCurrentThreadId[DllImport("kernel32.dll", EntryPoint="GetCurrentThreadId")]public static extern int GetCurrentThreadId ();// Win32: AttachThreadInput()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern int AttachThreadInput (int idAttach,int idAttachTo,int fAttach);// Win32: GetFocus()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern IntPtr GetFocus ();// Win32: SendMessage()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern int SendMessage (HandleRef hwnd,int wMsg,int wParam,int lParam);[DllImport("user32.dll", EntryPoint="SendMessage",CharSet=CharSet.Auto)]public static extern int SendMessageString (HandleRef hwnd,int wMsg,int wParam,StringBuilder lParam);// Win32: GetWindowText()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern int GetWindowText (IntPtr hwnd,StringBuilder lpString,int nMaxCount);// Win32: GetClassName()[DllImport("user32.dll",CharSet=CharSet.Auto)]private static extern int GetClassName (IntPtr hwnd,StringBuilder lpClassName,int nMaxCount);#endregion//enum HookTypeprivate enum HookType : int{//WH_JOURNALRECORD = 0,//WH_JOURNALPLAYBACK = 1,//WH_KEYBOARD = 2,//WH_GETMESSAGE = 3,//WH_CALLWNDPROC = 4,//WH_CBT = 5,//WH_SYSMSGFILTER = 6,//WH_MOUSE = 7,//WH_HARDWARE = 8,//WH_DEBUG = 9,//WH_SHELL = 10,//WH_FOREGROUNDIDLE = 11,//WH_CALLWNDPROCRET = 12,//WH_KEYBOARD_LL = 13,WH_MOUSE_LL = 14}// Filter function delegateprivate delegate int HookProc(int nCode, int wParam, IntPtr lParam);// **********************************************************************//指向钩子处理函数,该函数是自定义的而由Window系统调用的函数,即回调函数// **********************************************************************private const int WM_LBUTTONUP=0x0202;private const int WM_SETTEXT=0x000C;private const int WM_PAINT= 0x000F;private static IntPtr hookWnd =IntPtr.Zero;private static HandleRef txtHandle;private static StringBuilder lpClassName = new StringBuilder("Hello!",256);//*************************************************************************public static bool SetHook(HandleRef myHandle){IntPtr dllInstance = GetModuleHandle("MHook.dll");if (dllInstance==IntPtr.Zero){return false;}else{txtHandle = myHandle;hookWnd=SetWindowsHookEx(HookType.WH_MOUSE_LL,new HookProc(MouseHook.MyMouseProc),dllInstance,0);if (hookWnd==IntPtr.Zero){return false;}return true;}}public static void StopHook(){UnhookWindowsHookEx(hookWnd );}private static int MyMouseProc(int nCode, int wParam, IntPtr lParam){if(nCode