日期:2014-05-18  浏览次数:21340 次

内存已损坏提示,解决马上给分
直接贴代码:
尝试读取或写入受保护的内存。这通常指示其他内存已损坏
C# code

 /// <summary>
        /// 应用程序的主入口点。---------****在这里报这个错误
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GUI());
        }



C# code

 public partial class GUI : Form
    {

        DataTable m_GradeTable  = new DataTable();
        Hashtable Axlist = new Hashtable();
        public delegate void MyEventHandler(Object sender,EventArgs e);
        public event MyEventHandler MyEvent;
        
        public GUI()
        {
            InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
            this.bdsGrade.AutoGenerateColumns = false;
            dataGridView1.DataSource = MachineInfoBLL.GetMachineInfoAll();

            m_GradeTable.Columns.Add("序号", typeof(string));
            m_GradeTable.Columns.Add("登记号或卡号", typeof(string));
            m_GradeTable.Columns.Add("姓名", typeof(string));
            m_GradeTable.Columns.Add("时间", typeof(string));
            m_GradeTable.Columns.Add("设备名称", typeof(string));
            m_GradeTable.Columns.Add("比对方式", typeof(string));
            MyEvent += Connect;
         
        }
        private void Form1_Load(object sender, EventArgs e)
        {
           
        }
        private void Connect(object sender,EventArgs e)
        {
           
            Axzkemkeeper.AxCZKEM ax = (Axzkemkeeper.AxCZKEM)sender;
            int rowindex = dataGridView1.CurrentCell.RowIndex;
            string ip = dataGridView1.Rows[rowindex].Cells[3].Value.ToString();
            int port = int.Parse(dataGridView1.Rows[rowindex].Cells[4].Value.ToString());
            int commkey = MachineInfoBLL.GetMachinePWD(ip);
                bool flag = false;
                int errorCode = 0;
                ax.SetCommPassword(commkey);                
                flag = ax.Connect_Net(ip, port);



                if (flag)
                {


                    ax.RegEvent(1, 32767);
                    ax.OnAttTransactionEx += new Axzkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(ax_OnAttTransactionEx);
                    dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value ="已连接";
                }
                else
                {
                    ax.GetLastError(ref errorCode);
                    MessageBox.Show("Unable to connect to device, Error Code: " + errorCode.ToString());
                }
               
              
       
        }
      
        private void ax_OnAttTransactionEx(object sender, Axzkemkeeper._IZKEMEvents_OnAttTransactionExEvent e)
        {

            int dwMachineNumber = 0;
            int dwinfo = 2;
            int dwvalues = 0;
            //MessageBox.Show("a");
            Axzkemkeeper.AxCZKEM ax = (Axzkemkeeper.AxCZKEM)sender;
            ax.GetDeviceInfo(dwMachineNumber, dwinfo, ref dwvalues);
            DateTime now = DateTime.Parse(e.year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute + ":" + e.second);
           // MessageBox.Show("b");
            if (CheckInOutBLL.AddCheckInOutInfo(e.enrollNumber, now, e.verifyMethod.ToString(), dwvalues.ToString(), now))
            {
              
            if (e.verifyMethod == 1)
                m_GradeTable.Rows.Add(new string[] { (bdsGrade.Rows.Count + 1)