我用mscomm和teechart做了一个数据串口通信实时通信软件  但是在用信号发生器实验时出现
comm.exe 中的 0x77266344 处有未经处理的异常: 0xC0000005: Access violation,下面是代码   求助!谢谢!
void CCommDlg::OnComm() 
{
if(stop)return;
VARIANT m_input1;
COleSafeArray m_input2;
long length,i;
BYTE data[600];
CString str;
if(m_Comm.GetCommEvent()==2)//接收缓冲区内有字符
{
m_input1=m_Comm.GetInput();//读取缓冲区内的数据
m_input2=m_input1;//将VARIANT型变量转换为ColeSafeArray型变量
length=m_input2.GetOneDimSize();//确定数据长度
for(i=0;i<length;i++)
m_input2.GetElement(&i,data+i);//将数据转换为BYTE型数组 for(i=0;i<length;i++)//将数组转换为Cstring型变量
{
CFile file;
CString tempstr;
BYTE a=* (char *)(data+i);
BYTE b=* (char *)(data+(++i));
float c=(float)a+(float)(b%10)/10;
str.Format("%2.1f ",c);//将a格式化
if (str.GetLength()<5) str="0"+str;
str = str.Right(5);
调试停在这里 m_ReceiveData+=tempstr;//将刚采集的数加到编辑框中
//LineHight[121]=a;
Display();//对数据显示前的处理
//将数据保存到文件中
if (m_ReceiveData.GetLength()>=600)//600个字符刚好对应120个数据
{
CStdioFile readfile; 
CString readstr,readstr2;
if(readfile.Open(FilePath,CFile::modeRead))
{
while(readfile.ReadString(readstr))//逐行查询,至到文件尾
{
readstr2+=readstr;
}
readfile.Close();
} if (file.Open(FilePath,CFile::modeCreate|CFile::modeReadWrite))
{
file.Write(readstr2,readstr2.GetLength());//原来的数据
  file.Write(m_ReceiveData,600);//写入新的120个数据
file.Close();
m_ReceiveData="";//清除编辑框内容
break;
}
}
}
}
UpdateData(FALSE);//更新编辑框内容
}
“comm.exe”: 已加载“C:\Users\user\Desktop\串口\串口温度数据采集并实时显示\src\Debug\comm.exe”,已加载符号。
“comm.exe”: 已加载“C:\Windows\System32\ntdll.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\kernel32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\KernelBase.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\mfc100d.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msvcr100d.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\user32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\gdi32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\lpk.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\usp10.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msvcrt.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\shlwapi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16661_none_ebfb56996c72aefc\comctl32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\advapi32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\sechost.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\rpcrt4.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msimg32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\oleaut32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\ole32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\apphelp.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\AppPatch\AcLayers.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\sspicli.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\shell32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\userenv.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\profapi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\winspool.drv”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\mpr.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\AppPatch\AcGenral.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\uxtheme.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\winmm.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\samcli.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msacm32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\version.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\sfc.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\sfc_os.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\dwmapi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\setupapi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\cfgmgr32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\devobj.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\urlmon.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\wininet.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\iertutil.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\crypt32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msasn1.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\AppPatch\AcXtrnal.dll”,Cannot find or open the PDB file
FTH: (7348): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***
“comm.exe”: 已加载“ImageAtBase0x220000”,“包括”/“排除”设置禁用了加载功能。
“comm.exe”: 已卸载“ImageAtBase0x220000”
“comm.exe”: 已加载“C:\Windows\System32\shunimpl.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\SortServer2003Compat.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\imm32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msctf.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\mfc100chs.dll”,未使用调试信息生成二进制文件。
“comm.exe”: 已加载“E:\Program Files\safemon\safemon.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\msvcp60.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\psapi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\ws2_32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\nsi.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bd\comctl32.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\cryptbase.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\clbcatq.dll”,Cannot find or open the PDB file
“comm.exe”: 已加载“C:\Windows\System32\MSCOMM32.OCX”,无法找到或打开所需的 DBG 文件。
“comm.exe”: 已加载“C:\Windows\System32\sxs.dll”,Cannot find or open the PDB file
comm.exe 中的 0x7585e10a 处最可能的异常: 0xC0000005: 读取位置 0x003d0480 时发生访问冲突
comm.exe 中的 0x7585e10a 处有未经处理的异常: 0xC0000005: 读取位置 0x003d0480 时发生访问冲突

解决方案 »

  1.   

    tempstr没有赋值,那你使用来有什么用了
      

  2.   

    Debug下call stack看看函数调用堆栈,找到出错的函数先~
      

  3.   

    调试停在这里  m_ReceiveData+=tempstr;//将刚采集的数加到编辑框中    求助 谢谢!
    能告诉我具体的解决方法吗
      

  4.   

    有时调试出现
    friend CStringT operator+(
    _In_ const CStringT& str1,
    _In_ const CStringT& str2)
    {
    CStringT strResult( str1.GetManager() );调试停在这句 Concatenate( strResult, str1, str1.GetLength(), str2, str2.GetLength() ); return( strResult );
    }输出:> comm.exe!ATL::operator+(const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & str1="0?", const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & str2={...})  行 2295 + 0xb 字节 C++
      

  5.   

    当调试停到m_ReceiveData+=str自动窗口显示 this 0x113c0887 {CCommDlg hWnd=???} CCommDlg * const
    跪求帮助!
      

  6.   

    如果我用单片机一位一位数字的发送和接受数据则不会出项上述的问题,Teechart能够显示曲线
    求助!大侠  请问到底问题出在哪里 ?是与通信协议有关吗?跪求