在线急请高手解决:Unhandled exception in NServer.exe(MFC42D.DLL):0xC0000005:Access Violation
错误信息:Unhandled exception in NServer.exeMFC42D.DLL):0xC0000005:Access Violation
出错代码:
//The index of the new item if successful or -1 otherwise.
1)this-> m_list.SetItemText(0,1, "adlf "); //CListCtrl m_list;
2)this-> m_list.SetItemText(0,2, "asdfk ");//this->
3)this-> m_list.SetItemText(0,3, "sadhf ");//this->
4)this-> m_list.SetItemText(0,4, "324lds ");//this->
当我运行DebugF10调试到1)语句时,出现上面的错误提示,网上也有类似的问题,但是还是没有弄明白.
详细代码如下:
void CDlgMain::AddLog(CString ComeCode,CString ComeName,CString LogCont)
{
CTime tm = CTime::GetCurrentTime();
CString strTM = " ";
int nIndex = 0;
strTM.Format( "%04d-%02d-%02d %02d:%02d:%02d ",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
try{
CAllIndexRst dIndex;
if(dIndex.IsOpen())
dIndex.Close();
//打开日志信息表
dIndex.m_strFilter = "IndexType = 101 ";
dIndex.Open();
//若日志信息表存在,则将索引值加1(表示添加一条日志记录)
if(!dIndex.IsEOF()){
nIndex = dIndex.m_IndexValue + 1;
dIndex.Edit();
dIndex.m_IndexValue = nIndex;
dIndex.Update();
}
else{
//若日志信息表不存在,则将索引值赋100,同时添加一条新记录(表示建立日//志信息表)
nIndex = 100;
dIndex.AddNew();
dIndex.m_IndexValue = nIndex;
dIndex.Update();
}
dIndex.Close();
if(nIndex <= 0 )
return;
CLogRst dLog;//////////以下对日志信息表进行操作
if(dLog.IsOpen())
dLog.Close();
dLog.m_strFilter = "1 = 0 ";
dLog.Open();
dLog.AddNew();//往日志信息表中添加一新记录
dLog.m_LogIndex= nIndex;//索引号
dLog.m_LogTime= strTM;//日志创建时间
if(strlen(ComeCode) <= 0)//用户编号
dLog.m_ComeUserCode = 0;
else
dLog.m_ComeUserCode = atoi(ComeCode);
//Convert string to integer,return an integer of which input //characters after convert
dLog.m_ComeUserName = ComeName;//用户姓名
dLog.m_LogContent= LogCont;//日志内容
dLog.Update();//更新
dLog.Close();
}
catch(...){;}
CString tempstr = " ";
tempstr.Format( "%d " , nIndex);
//以下在日志信息表浏览控件中添加一条新日志记录this->
this-> m_list.InsertItem(0, "12 ");//0表示插入位置//int nItem=
//The index of the new item if successful or -1 otherwise.
this-> m_list.SetItemText(0,1, "adlf ");//CListCtrlm_list;
this-> m_list.SetItemText(0,2, "asdfk ");//this->
this-> m_list.SetItemText(0,3, "sadhf ");//this->
this-> m_list.SetItemText(0,4, "324lds ");//this-> this->
//SetItemText(int nItem, int nSubItem, LPTSTR lpszText )
//FUNCTION:Changes the text of a list view item or subitem.
//RETURN:Nonzero if successful; otherwise zero.
}
[解决办法]
1、this指针是否有效?
2、m_list对象是否存在,且有效?
3、通过查看它们的值来判断。