调试断言失败发生在wincrore.cpp ....行号:888 [英] Debug Assertion Failed occurs in wincrore.cpp....line no:888
问题描述
我是vc ++的新手.通过使用辅助线程,IAM尝试使用UpdateAllViews()发送数据(可以从文件中读取)以查看....在辅助线程的帮助下...它工作正常...但是使用updateallviews的方法是iam ..,将发生这些错误.(在DeBUG模式下)..但在RELEASE模式下..都可以正常工作.以下是我的示例代码:
在Docclass中
< u> FileReadDisplayDoc.h
</u>
unsigned long strTemp;
< u> FileReadDisplayDoc.cpp</u>
CWinThread pThreadObj;
void CFileReadDisplayDoc :: OnToolbarSelectFile()
{
//WithoutThreadSendData();//我的函数
WithThreadSendData();//我的函数
}
void CFileReadDisplayDoc :: WithoutThreadSendData()
{
CString m_strFileName;
char strRead [3];
FILE * fTP;
char strFileFilter [] = {文本文件(* .TXT)| * .TXT | DOC FILES(*.DOC)| * .DOC | ALL文件(*.*)| *.* ||"};
CFileDialog FileDlg(TRUE,".BMD",",0,strFileFilter);
如果(FileDlg.DoModal()== IDOK)
{
m_strFileName = FileDlg.GetFileName();
fTP = fopen(m_strFileName,"r");
while(!feof(fTP))
{
无符号长nDataVal = 0;
char * nStatus = NULL;
fread(strRead,3,1,fTP);
strRead [2] =''\ 0'';
nDataVal = strtoul(strRead,& nStatus,10);
strTemp =(无符号字符)nDataVal;
睡眠(100);
< b> UpdateAllViews(NULL,strTemp,NULL);</b>
//这里调试断言失败....在所有视图中更新...
//这些问题的解决方案是什么...?如果有人..可能... ,,
//plz将正确的代码发送到我的邮件:t.r.yuva@gmail.com
< b>(或)</b>
yuvifun(strTrackData);//用于无线程发送数据
//fun()将数据发送到视图
}
fclose(fTP);
}
}
//我的线程
UINT DataSendThread(LPVOID ptrTPThreadParam)
{CFileReadDisplayDoc * pdocObj =(CFileReadDisplayDoc *)ptrTPThreadParam;
pdocObj-> WithoutThreadSendData();
返回0;
}</u>
void CFileReadDisplayDoc :: WithThreadSendData()
{
pThreadObj = AfxBeginThread(DataSendThread,this,THREAD_PRIORITY_LOWEST,0,CREATE_SUSPENDED,0);
pThreadObj-> ResumeThread();
}
//在view.cpp
void CDisplay :: OnUpdate(CView * pSender,LPARAM lHint,CObject * pHint)
{
unsigned char strD [2];
CString getv;
strD [0] = lHint;
getv.Format(%d",strD [0]);
SetDlgItemText(IDE_DDISPLAY,getv);
}
解决方案是什么......调试断言失败错误发生在第888行:(在调试时发生在更新所有视图中...
在我的邮件中发布解决方案:tryuva@gmail.com
Iam new to vc++. By using worker thread, iam try to send data(that can be read from the file) to view...,using UpdateAllViews().The debug assertion fails occursin updateallviews...if iam using function to send a data to view continuously with the help of worker thread...it works perfect...but iam using updateallviews means..,these error will be occured..(in DeBUG mode)..but in RELEASE mode..both r working fine..coming below is my sample code:
in Docclass
<u>FileReadDisplayDoc.h
</u>
unsigned long strTemp ;
<u>FileReadDisplayDoc.cpp</u>
CWinThread pThreadObj;
void CFileReadDisplayDoc::OnToolbarSelectFile()
{
//WithoutThreadSendData() ;//my functions
WithThreadSendData() ;//my functions
}
void CFileReadDisplayDoc::WithoutThreadSendData()
{
CString m_strFileName ;
char strRead[3] ;
FILE *fTP ;
char strFileFilter[] = {"TEXT FILES (*.TXT) |*.TXT| DOC FILES(*.DOC) |*.DOC|ALL Files(*.*)|*.*||"} ;
CFileDialog FileDlg(TRUE, ".BMD","", 0, strFileFilter) ;
if (FileDlg.DoModal()==IDOK)
{
m_strFileName = FileDlg.GetFileName() ;
fTP = fopen(m_strFileName, "r") ;
while(!feof(fTP))
{
unsigned long nDataVal = 0 ;
char *nStatus = NULL ;
fread(strRead,3,1,fTP) ;
strRead[2] = ''\0'' ;
nDataVal=strtoul(strRead, &nStatus, 10) ;
strTemp = (unsigned char)nDataVal ;
Sleep(100) ;
<b> UpdateAllViews(NULL,strTemp ,NULL) ;</b>
//here Debug assertion failed....in update all view...
//what''s the solution for these type of problems...?if anyone..possible...,,?
//plz send correct code to my mail: t.r.yuva@gmail.com
<b>(or)</b>
yuvifun(strTrackData);//for without thread send data
//fun() to send data to view
}
fclose(fTP) ;
}
}
//my thread
UINT DataSendThread(LPVOID ptrTPThreadParam)
{ CFileReadDisplayDoc *pdocObj = (CFileReadDisplayDoc*) ptrTPThreadParam;
pdocObj->WithoutThreadSendData();
return 0;
}</u>
void CFileReadDisplayDoc::WithThreadSendData()
{
pThreadObj = AfxBeginThread(DataSendThread,this,THREAD_PRIORITY_LOWEST,0,CREATE_SUSPENDED,0) ;
pThreadObj->ResumeThread() ;
}
//in view.cpp
void CDisplay::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
unsigned char strD[2] ;
CString getv ;
strD[0] = lHint ;
getv.Format("%d",strD[0]) ;
SetDlgItemText(IDE_DDISPLAY,getv) ;
}
What''s the solution....for Debug assertion failed error occurs in line no : 888 wincrore.cpp (while debugging it occurs in Update All Views...
post solution to my mail : t.r.yuva@gmail.com
推荐答案
正确使用工作线程很棘手,请看一下Joseph M. Newcomer的使用Worker Threads"[ ^ ].
:)
Correctly using worker threads is tricky, please have a look at Joseph M. Newcomer''s "Using Worker Threads" [^].
:)
这篇关于调试断言失败发生在wincrore.cpp ....行号:888的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!