fclose出错 引起程序崩溃 求解决办法
出错信息
应用程序 Gateway.exe 产生了一个应用程序错误 此错误发生在 01/27/2009 @ 02:37:05.208 所产生的意外情况为 c0000005,在地址 77BA1A02 (msvcrt!fclose)处
有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。
错误应用程序 Gateway.exe,版本 1.0.0.1,错误模块 msvcrt.dll,版本 7.0.3790.3959,错误地址 0x00031a02。
有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。
我认为是fclose关闭异常
void AddStateRecord( const char *format, ... )
{
va_list marker;
va_start( marker, format ); // Initialize variable arguments.
vsprintf( logbuf, format, marker );
va_end( marker ); // Reset variable arguments.
FILE *flog = NULL;// 系统日志文件句柄
#ifdef _DEBUG
OutputDebugString( logbuf );
#endif
CString FilePath = csWorkLogPath;
CTime time = CTime::GetCurrentTime();
CString m_strTime = time.Format("%Y-%m-%d-%H");
FilePath = FilePath+m_strTime+".txt";
flog = fopen( FilePath, "aw+" );
if( NULL == flog )
{
#ifdef _DEBUG
OutputDebugString( "fopen error!");
OutputDebugString( FilePath);
#endif
return;
}
//fflush( flog );
fwrite( logbuf, 1, strlen( logbuf ), flog );
fclose (flog);
}