日期:2014-05-19  浏览次数:20844 次

上贴没说清楚问题,还是线程钩子问题??????????????????????????
全局钩子一点问题也没有,线程钩子就要报错。
按照下面的代码,线程钩子,金山词霸进程里的其中一个线程。
报错:xdict.exe   中的   0x01f73772   处未处理的异常:   0xC0000005:   写入位置   0x00000000   时发生访问冲突。
为什么全局钩子就没有问题,线程钩子就要报错呢?各位高手指教啊,谢谢,非常感谢。

using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;
using   System.Reflection;
using   System.Runtime.InteropServices;
using   System.Diagnostics;

namespace   WindowsApplication3
{
        public   partial   class   Form1   :   Form
        {
                [DllImport( "user32.dll ",   EntryPoint   =   "SetWindowsHookEx ",   CharSet   =   CharSet.Auto)]
                public   static   extern   IntPtr   SetWindowsHookEx(int   idHook,   ClassLibrary2.HookCallBack   lpfn,   IntPtr   hMod,   int   dwThreadId);

                public   Form1()
                {
                        InitializeComponent();
                }
                int   threadid=0;
                const   int   WH_GETMESSAGE   =   3;
                private   void   button1_Click(object   sender,   EventArgs   e)
                {

                        Process[]   proe   =   Process.GetProcesses();
                        foreach   (Process   proc   in   proe)//遍历所有进程
                        {

                                foreach   (ProcessThread   var   in   proc.Threads)     //得到进程的所有线程
                                {
                                        if   (proc.ProcessName   ==   "xdict ")     //如果是金山词霸进程。
                                        {
                                                threadid   =   var.Id;                   //得到其中一个线程
                                                break;
&nbs