在ListCtrl里面加东西,DEBUG完全正常,RELEASE显示乱字符加内存访问出错
SerialPortComm.MFC.exe 中的 0x7c938fea 处最可能的异常: 0xC0000005: 写入位置 0x00000010 时发生访问冲突
HEAP[SerialPortComm.MFC.exe]: Invalid Address specified to RtlFreeHeap( 00150000, 00150258 )
   之类的,0x7c938fea属于ntdll.dll,堆栈没信息
,退出程序显示Windows 已在 SPC.exe 中触发一个断点。
其原因可能是堆被损坏,这说明 SPC.exe 中或它所加载的任何 DLL 中有 Bug。
原因也可能是用户在 SPCC.exe 具有焦点时按下了 F12。
输出窗口可能提供了更多诊断信息。以下是在ListCtrl里面添加项目的代码,优化已经全部关掉了
另外,如果打开优化的话lParam就是空的,反汇编在后面(虽然这不是关键问题)
使用VC++ 2008,多谢各位了~
lsc_info是自定义结构体;m_lsc_monitor是ListCtrl的变量
lsc_param是vector,防止内存泄漏用的,可以无视
中间有一些无关紧要的去掉了多谢各位了~! int nIndex = m_lsc_monitor.GetItemCount(); lsc_info* lsc_info_param = new lsc_info; LV_ITEM lvitem_template = {LVIF_TEXT| LVIF_PARAM| LVIF_GROUPID, //mask
nIndex, //iItem
0, 0, 0, NULL, 0, 0, NULL, 0, 0, 0, NULL, NULL, 0};
LV_ITEM* lvitemAdd =new LV_ITEM(lvitem_template); CString* str_debug = new CString; 
if (Serial) {
str_debug->Format(_T("%X"),Serial);
}
else {
str_debug->Append(_T("N/A"));
}
LPTSTR lptstr_tmp = new _TCHAR[10];
_tcscpy_s(lptstr_tmp, str_debug->GetLength()+1, str_debug->GetBuffer());
lvitemAdd->pszText = lptstr_tmp;
lvitemAdd->cchTextMax = str_debug->GetLength()+1; lsc_param.push_back(lsc_info_param); lvitemAdd->lParam = reinterpret_cast<LPARAM>(lsc_info_param);
m_lsc_monitor.InsertItem(lvitemAdd); ;最快速度优化
;lvitemAdd.lParam = reinterpret_cast<LPARAM>(lsc_info_param);
;m_lsc_monitor.InsertItem(&lvitemAdd);
004018B7  mov         eax,dword ptr [ebx+98h] 
004018BD  mov         edi,dword ptr [__imp__SendMessageW@16 (4091B0h)] 
004018C3  lea         edx,[esp+6Ch] 
004018C7  push        edx  
004018C8  push        0    
004018CA  push        104Dh 
004018CF  push        eax  
004018D0  mov         dword ptr [esp+9Ch],esi 
004018D7  call        edi  
;无优化
;lvitemAdd.lParam = reinterpret_cast<LPARAM>(lsc_info_param);lsc_info_param;
00401BD6  mov         edx,dword ptr [ebp-9Ch] 
00401BDC  mov         dword ptr [ebp-74h],edx  m_lsc_monitor.InsertItem(&lvitemAdd);
00401BDF  lea         eax,[ebp-94h] 
00401BE5  push        eax  
00401BE6  mov         ecx,dword ptr [ebp-0B4h] 
00401BEC  add         ecx,78h 
00401BEF  call        CListCtrl::InsertItem (403FF0h) yo

解决方案 »

  1.   

    错了,release下不能调试。取消。
      

  2.   

    关键是我也不知道。。ntdll.dll内部出错,没看出是那里调用进去的
    估计是InsertItem有点问题吧
      

  3.   

    Release可以调试(设置调试信息)。。但是出错貌似不在这个函数内部
    另外,试着把DEBUG版的_DEBUG定义去掉变成NDEBUG也没出错
      

  4.   

    堆栈看不成,中间被“无法得到信息”隔开了。。解决了,貌似是用了LVIF_GROUPID就出错。。晕死,是MS自己的BUG么?DEBUG版明明又能用。。
    也就是没办法用分组了啊。。虽然不是必须的,但是如果一定要实现的话就要用托管了么晕