// Log assertion to file and issue warning but don't issue a
// message box. To call stack trace assert uncomment the
// lines indicated
void GioAssertFailedLine(LPCSTR file, int line, LPCSTR code)
{
static StartStopAssertLog Monitor;
CTime Time=CTime::GetCurrentTime();
CString TimeString=Time.Format("%Y %B %d, %H:%M:%S");
char Description[1024];
sprintf(Description,"================================\r\n"
"ASSERTION FAILED\r\nProg : %s\r\nFile : %s\r\nLine : "
"%i\r\nTime : %s\r\nExpr : %s\r\n",
(LPCSTR)AfxGetAppName(),
file?(LPCSTR)file:"?",
(int)line,
(LPCSTR)TimeString,
code?(LPCSTR)code:"");
TRACE0(Description); // Show it also on the debug trace
try
{
CFile File;
if (File.Open("C:\\ASSERT.LOG",
CFile::modeCreate|CFile::modeNoTruncate|
CFile::modeWrite|CFile::shareDenyWrite))
{
File.SeekToEnd();
File.Write(Description,lstrlen(Description));
// Do a stack trace, if you want to, using MFC's
// AfxDumpStack. If you want a stack trace, just
// uncomment these four lines. It is slow and
// boundschecker reports some warnings, but it works.
//AfxDumpStack is only available with version 6 of MFC
//CFile * pOldFile=afxDump.m_pFile;
//afxDump.m_pFile=&File;
//AfxDumpStack();
//afxDump.m_pFile=pOldFile;
File.Close();
}
else
MessageBox(AfxGetMainWnd()->GetSafeHwnd(),
Description,"GIODEBUG",MB_OK|MB_ICONERROR);
}
catch(...)
{
MessageBox(AfxGetMainWnd()->GetSafeHwnd(),
Description,"GIODEBUG",MB_OK|MB_ICONERROR);
}
MessageBeep(0);
ShowAssertWarning();
}