【求助】 0x5743fb75 处未处理的异常: 0xC0000005: 写入位置 0xfffffffb 时发生访问冲突
软件环境是VS2008,在程序运行的时候没有错误,但是只要我一关闭程序,就会出现这个错误。
应该是在这个事件出的错,但是具体在哪错的,我也不知道。
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;
}