【求帮助】 0x5743fb75 处未处理的异常: 0xC0000005: 写入位置 0xfffffffb 时

C++语言 码拜 8年前 (2016-02-03) 1093次浏览
软件环境是VS2008,在程序运行的时候没有错误,但是只要本人一关闭程序,就会出现这个错误。【求帮助】 0x5743fb75 处未处理的异常: 0xC0000005: 写入位置 0xfffffffb 时
应该是在这个事件出的错,但是具体在哪错的,本人也不知道。

void CGridCtrlTestDlg::DataFromGrid() //把数据从表格中读取到uc_send[][]数组中
{
	int uc_send_index=0; //用来作为uc_send二维数组的下标
	int num_Buf=((MyGridRow-1)*(MyGridCol-2)); //wBuffer数组的项数
	BYTE wBuffer[(MyGridRow-1)*(MyGridCol-2)][8] ; //对应gridctrl的表格(不包括固定行和固定列)
	BYTE *str;
	str=new BYTE;
	int i_Buf=0;
	CString c_str;
	//把GridCtrl表格中的数据填充到wBuffer中
	for (int r=1;r<m_pGrid.GetRowCount();r++)
	{
		for (int c=2;c<m_pGrid.GetColumnCount();c++) 
		{
			//获取单元格数据
			c_str=m_pGrid.GetItemText(r,c);
			str=(BYTE *)c_str.GetBuffer(0);
			int i=0;
			while (str[i]!=""\0"" && i<7)
			{
				wBuffer[i_Buf][i]=str[i];
				i++;
			}
			wBuffer[i_Buf][i]=""\0"";
			i_Buf++;
		}
	}
	//把 信道信息 COPY到uc_send二维数组中,暂时先不添加地址信息
	memset(uc_send,0xff,275*20);
	int temp=0,index=0,k_temp=0;
	float f_temp=0;
	while(index<num_Buf)
	{
		int m=4; //留4位给地址
		//接收频率
		f_temp=atof((char *)wBuffer[index]);
		f_temp*=100000;
		temp=f_temp;
		
		if (temp != 0) //空行的话,直接填充0xFF
		{
			index++;
			k_temp=int_10to16(temp%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/100)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/10000)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/1000000)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			//发射频率
			f_temp=atof((char *)wBuffer[index]);
			f_temp*=100000;
			temp=f_temp;
			/*if (0!=temp)
			{
				temp+=12500;
			}*/
			index++;
			k_temp=int_10to16(temp%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/100)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/10000)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			k_temp=int_10to16((temp/1000000)%100);
			uc_send[uc_send_index][m]=k_temp;
			m++;
			//  QT/DQT解码
			if (wBuffer[index][0]==""D"") //为数字亚音频DQT
			{
				BYTE *b_Buf;
				b_Buf=new BYTE[3];
				b_Buf[0]=wBuffer[index][1];
				b_Buf[1]=wBuffer[index][2];
				b_Buf[2]=wBuffer[index][3];
				temp=atoi((char *)b_Buf);
				for (int n=0;n<105;n++) //遍历DCS_TAB[]数组,找到对应的下标
				{
					if (temp==DCS_TAB[n])
					{
						if (wBuffer[index][4]==""I"")
						{
							uc_send[uc_send_index][m]=n+105+1;
							m++;
							uc_send[uc_send_index][m]=0;
							m++;
						}
						else  //=N
						{
							uc_send[uc_send_index][m]=n+1;
							m++;
							uc_send[uc_send_index][m]=0;
							m++;
						}
					}
				}
				b_Buf = NULL;
			} 
			else  //为亚音频QT
			{
				float n_float=atof((char *)wBuffer[index]);
				//temp=atoi((char *)wBuffer[index]);
				n_float *= 10; //自乘10,协议规定
				temp=n_float;
				uc_send[uc_send_index][m]=temp%256; //低八位
				m++;
				uc_send[uc_send_index][m]=temp/256; //高八位
				m++;
			}
			index++;
			//  QT/DQT编码
			if (wBuffer[index][0]==""D"") //为数字亚音频DQT
			{
				BYTE *b_Buf;
				b_Buf=new BYTE[3];
				b_Buf[0]=wBuffer[index][1];
				b_Buf[1]=wBuffer[index][2];
				b_Buf[2]=wBuffer[index][3];
				temp=atoi((char *)b_Buf);
				for (int n=0;n<105;n++) //遍历DCS_TAB[]数组,找到对应的下标
				{
					if (temp==DCS_TAB[n])
					{
						if (wBuffer[index][4]==""I"")
						{
							uc_send[uc_send_index][m]=n+105+1;
							m++;
							uc_send[uc_send_index][m]=0;
							m++;
						}
						else  //=N
						{
							uc_send[uc_send_index][m]=n+1;
							m++;
							uc_send[uc_send_index][m]=0;
							m++;
						}
					}
				}
				b_Buf = NULL;
			} 
			else  //为亚音频QT
			{
				float n_float=atof((char *)wBuffer[index]);
				//temp=atoi((char *)wBuffer[index]);
				n_float *= 10; //自乘10,协议规定
				temp=n_float;
				uc_send[uc_send_index][m]=temp%256; //低八位
				m++;
				uc_send[uc_send_index][m]=temp/256; //高八位
				m++;
			}
			index++;
			m++; //信令码
			m++; //保留
			uc_send[uc_send_index][19]=0x00; //更改
			//发射功率
			if (wBuffer[index][0]==""H"")
			{
				uc_send[uc_send_index][m]=0;
			} 
			else if (wBuffer[index][0]==""L"")
			{
				uc_send[uc_send_index][m]=1;
			}
			index++;
			m++;
			//宽窄带
			if (""W""==wBuffer[index][0])
			{
				uc_send[uc_send_index][m] |= 0x40; //BIT6置1
			} 
			else
			{
				uc_send[uc_send_index][m] &= 0xbf; //BIT6置0
			}
			index++;
			//PTT-ID
			if(!(strcmp((char *)wBuffer[index],"OFF")))
			{
				uc_send[uc_send_index][m] &= 0xfc; //BIT1,BIT0置00
			}
			else if (!(strcmp((char *)wBuffer[index],"BOT")))
			{
				uc_send[uc_send_index][m] &= 0xfd; //BIT1,BIT0置01
				uc_send[uc_send_index][m] |= 0x01;
			}
			else if (!(strcmp((char *)wBuffer[index],"EOT")))
			{
				uc_send[uc_send_index][m] |= 0x02; //BIT1,BIT0置10
				uc_send[uc_send_index][m] &= 0xfe;
			}
			else if (!(strcmp((char *)wBuffer[index],"BOTH")))
			{
				uc_send[uc_send_index][m] |= 0x03; //BIT1,BIT0置11
			}
			index++;
			//繁忙信道锁定
			if (""N""==wBuffer[index][1])
			{
				uc_send[uc_send_index][m] |= 0x04; //BIT3置1
			} 
			else
			{
				uc_send[uc_send_index][m] &= 0xf7; //BIT3置0
			}
			index++;
			//扫描添加
			if (""N""==wBuffer[index][1])
			{
				uc_send[uc_send_index][m] |= 0x04; //BIT2置1
			} 
			else
			{
				uc_send[uc_send_index][m] &= 0xfb; //BIT2置0
			}
			index++;
			m++;
			//信令码16
			temp=atoi((char *)wBuffer[index]);
			index++;
			uc_send[uc_send_index][16]=temp-1; //低八位
			m++;
			uc_send[uc_send_index][17]=0x00; //默认字节
			index++; //信道名称
		}
		else
		{
			index+=(MyGridCol-2); //
		}
		uc_send_index++;
	}
	//把 DTMF编码 COPY到uc_send二维数组中
	//编码码组
	int i=0;
	for (;i<15;i++)
	{
		//BYTE *str=new BYTE;
		CString str;
		char *pch=new char;
		int temp,dtmf_index=4; //num用于计数
		str.Format("%d",i_dtmf[i]);
		for (int m=0;m<str.GetLength();m++)
		{
			*pch=str.GetAt(m);
			temp=atoi(pch);
			uc_send[uc_send_index][dtmf_index]=temp;
			dtmf_index++;
		}
		for ( ;dtmf_index<=16;dtmf_index++) //剩余的填充FF
		{
			uc_send[uc_send_index][dtmf_index]=0xff;
		}
		uc_send_index++;
	}
	//本机 ID码
	BYTE chID[5];
	memset(chID,0,5);
	CString cstr;
	char *pch=new char;
	cstr.Format("%d",i_dtmf[i]);
	i++;
	int dtmf_index=14;
	for (int m=0;m<cstr.GetLength();m++)
	{
		*pch=cstr.GetAt(m);
		temp=atoi(pch);
		for (int k=4;k<=9;k++)
		{
			uc_send[uc_send_index][k]=0xff;
		}
		uc_send[uc_send_index][dtmf_index]=temp;
		dtmf_index++;
	}
	//PTT发送  这个和ID码在同一段地址
	if (0==i_dtmf[i])
	{
		uc_send[uc_send_index][19]=0x01; //PTT按下发送
	}
	if (1==i_dtmf[i])
	{
		uc_send[uc_send_index][19]=0x02; //PTT松开发送
	}
	i++;
	//DTMF码持续时间 DTMF码间断时间
	uc_send_index++;
	uc_send[uc_send_index][6]=i_dtmf[i];
	i++;
	uc_send[uc_send_index][7]=i_dtmf[i];
	i++;
	//把 可选参数编辑 COPY到uc_send二维数组中,暂时先不添加地址信息
	// 0E 20 地址
	uc_send_index++;
	dtmf_index=4;
	for (int i=0;i<15;i++)
	{
		uc_send[uc_send_index][dtmf_index]=i_select[i];
		i++;
		dtmf_index++;
	}
	// 0E 40 地址
	uc_send_index++;
	uc_send[uc_send_index][6]=i_select[i];
	i++;
	uc_send[uc_send_index][7]=i_select[i];
	i++;
	uc_send[uc_send_index][8]=i_select[i];
	i++;
	uc_send[uc_send_index][14]=i_select[i];
	i++;
	uc_send[uc_send_index][17]=i_select[i];
	i++;
	//信道名称
	for(int i_channel=1;i_channel<(MyGridRow-1)*(MyGridCol-2);i_channel++)
	{
		if(0==i_channel%num_channel_name)
		{
			//temp=atoi((char *)wBuffer[i_channel]);
			uc_send_index++;
			for(int num=0;num<6;num++)
			{
				uc_send[uc_send_index][num+4]=wBuffer[i_channel][num];
			}
			for(int num=10;num<20;num++) //剩余位填充0xFF
			{
				uc_send[uc_send_index][num]=0xFF;
			}
		}
	}
	//给uc_send二维数组添加地址信息
	uc_send_index=0; //归零
	BYTE address[2]; //存放地址信息
	address[0]=0x00; //信道信息
	address[1]=0x00;
	i=0;
	for(;i<128;i++)
	{
		uc_send[i][0]=head_write;
		uc_send[i][1]=address[0];
		uc_send[i][2]=address[1];
		uc_send[i][3]=0x10;
		address[1]+=0x10;
		if(0x00==address[1])
			address[0]+=1;
	}
	address[0]=0x0B; //DTMF编码
	address[1]=0x00;
	for(int k=0;k<15;k++)
	{
		uc_send[i][0]=head_write;
		uc_send[i][1]=address[0];
		uc_send[i][2]=address[1];
		uc_send[i][3]=0x10;
		i++;
		address[1]+=0x10;
		if(0x00==address[1])
			address[0]+=1;
	}
	address[0]=0x0C; //本机 ID码
	address[1]=0xA0;
	uc_send[i][0]=head_write;
	uc_send[i][1]=address[0];
	uc_send[i][2]=address[1];
	uc_send[i][3]=0x10;
	i++;
	address[0]=0x0C; //DTMF码持续时间
	address[1]=0xB0;
	uc_send[i][0]=head_write;
	uc_send[i][1]=address[0];
	uc_send[i][2]=address[1];
	uc_send[i][3]=0x10;
	i++;
	address[0]=0x0E; //对讲机可选功能信息
	address[1]=0x20;
	uc_send[i][0]=head_write;
	uc_send[i][1]=address[0];
	uc_send[i][2]=address[1];
	uc_send[i][3]=0x10;
	i++;
	address[0]=0x0E; //对讲机可选功能信息
	address[1]=0x40;
	uc_send[i][0]=head_write;
	uc_send[i][1]=address[0];
	uc_send[i][2]=address[1];
	uc_send[i][3]=0x10;
	i++;
	address[0]=0x10; //信道名称	
	address[1]=0x00;
	for(int k=0;k<128;k++)
	{
		uc_send[i][0]=head_write;
		uc_send[i][1]=address[0];
		uc_send[i][2]=address[1];
		uc_send[i][3]=0x10;
		i++;
		address[1]+=0x10;
		if(0x00==address[1])
			address[0]+=1;
	}
	str = NULL;
	pch = NULL;
}

今天就要交差了,一直卡在这里,求各位高手帮忙啊。小弟最后的70分全部奉送。谢谢。

解决方案:10分
看你的析构函数中是不是delete/free掉了一个空指针/野指针!
解决方案:10分
这个问题应该是用类new出来的东西  你程序结束后自动释放 你可能没判空 释放空指针 或多次释放
多看看 析构函数 那地方都释放没有 F9 断点  F10 F11 单步跟踪
解决方案:10分
检查下拷贝构造函数和析构函数!
假如析构函数没有问题,可能是调用默认构造函数引起的,深拷贝和浅拷贝。
解决方案:10分
再看了下你的代码,
你每次new出来的地址都没有delete释放啊,而是又是new新的地址空间?
注意每次new/delete配套使用,当不需要的时候要的了delete掉!防止内存泄漏!
解决方案:10分
在你的main挂掉了的话,有可能是你的在delete 你的对象挂掉了,或你是在add 你的对象,在析构的时候没有remove掉该对象,只有这两种可能了。
解决方案:10分
单步调试 先定位出错语句
解决方案:10分
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明【求帮助】 0x5743fb75 处未处理的异常: 0xC0000005: 写入位置 0xfffffffb 时
喜欢 (0)
[1034331897@qq.com]
分享 (0)