写Log函数

CRITICAL_SECTION pCs;

void WriteLog(char* pFile, char* pMsg)

 { 

 ::EnterCriticalSection(&pCs); 

 try 

{  

FILE* pLog = fopen(pFile,"a"); 

 fprintf(pLog,pMsg);  

 fclose(pLog); 

 }

 catch(...)

 {} 

 ::LeaveCriticalSection(&pCs);

}  

 

 long nError = GetLastError(); 

 char pTemp[121];  sprintf(pTemp, "OpenFile failed, error code = %d/n", nError); 

 WriteLog(pLogFile, pTemp);

你可能感兴趣的:(file)