栈error,急,求助!!

zhanguo77 zhanguo77 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用visual studio MFC做了一个程序,有点击按钮,弹出【打开文件】对话框和【保存文件】对话框的功能的按钮,
有时候点击按钮的时候就出现栈error。请问是什么原因,怎么解决?
我是新手,请解说的详细点啊,拜托了。
图片是弹出error的对话框。

还有按钮函数的代码。

void FMLogicName::OpenLogicNameFile()
{
CString strFileName;
CStdioFile file;
CFileDialog savedlg(true,
_T("csv"),
_T(""),
OFN_OVERWRITEPROMPT|OFN_CREATEPROMPT,
_T("CSV Files (*.csv)|*.csv")
,NULL);

if (savedlg.DoModal() == IDOK)
{
strFileName = savedlg.GetPathName();
if (!file.Open (strFileName,CFile::modeReadWrite | CFile::typeText))
{
MessageBox(_T("文件被打开"),"FM Radio",MB_ICONWARNING);
return;
}
else
{
CString szFilePath = _T("FM Radio,,");
CString strline;
file.ReadString(strline);
if(strline != szFilePath)
{MessageBox(_T("不是FM Radio文件"),"FM Radio",MB_ICONWARNING);return;}

file.ReadString(strline);
file.ReadString(strline);
file.ReadString(strline);
file.ReadString(strline);

while(file.ReadString(strline))
{
int nIndex = m_listctrl1.GetItemCount();

int comma[2];
int k=0;
for(int i=0; i<strline.GetLength(); i++)
{
if(strline[i]==','){comma[k]=i;k++;}
}

CString str1,str2,cnum,RowNo;
if(nIndex<9)RowNo.Format("00%d",nIndex+1);
else if(nIndex<99)RowNo.Format("0%d",nIndex+1);
else RowNo.Format("%d",nIndex+1);
LPSTR pnum = (LPSTR)(LPCSTR)RowNo;
for(int i=comma[0]+1; i<comma[1]; i++)str1+=strline[i];

LPSTR pstr1 = (LPSTR)(LPCSTR)str1;
for(int i=comma[1]+1; i<strline.GetLength(); i++)str2+=strline[i];
LPSTR pstr2 = (LPSTR)(LPCSTR)str2;

LV_ITEM lvitemAdd = {0};
lvitemAdd.mask = LVIF_TEXT;
lvitemAdd.iItem = nIndex ;
lvitemAdd.iSubItem = 0;
lvitemAdd.pszText = pnum;

if (m_listctrl1.InsertItem(&lvitemAdd) != -1)
{
LV_ITEM lvitem1 = {0};
lvitem1.mask = LVIF_TEXT;
lvitem1.iItem = nIndex ;
lvitem1.iSubItem = 1;
lvitem1.pszText = pstr1;

LV_ITEM lvitem2 = {0};
lvitem2.mask = LVIF_TEXT;
lvitem2.iItem = nIndex ;
lvitem2.iSubItem = 2;
lvitem2.pszText = pstr2;

m_listctrl1.SetItem(&lvitem1);
m_listctrl1.SetItem(&lvitem2);
}
}
}
file.Close();
}
}


Dubug时候,自动中断的中断点。在dbgheap.c文件里,不是我的自己写的文件。

if (!CheckBytes(pbData(pHead) + pHead->nDataSize, _bNoMansLandFill, nNoMansLandSize))
{
if (pHead->szFileName)
{
_RPT5(_CRT_ERROR, "HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
"CRT detected that the application wrote to memory after end of heap buffer.\n"
_ALLOCATION_FILE_LINENUM,
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead),
pHead->szFileName,
pHead->nLine);//debug的中断点在这行
}
else
{
_RPT3(_CRT_ERROR, "HEAP CORRUPTION DETECTED: after %hs block (#%d) at 0x%p.\n"
"CRT detected that the application wrote to memory after end of heap buffer.\n",
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));
}
}
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
zhanguo77
VC/MFC 16,550 成员 421,606 内容