BOOL WriteLog(const char *str, ...)
{
char *szLogFileName = (char *)malloc(MAX_PATH*sizeof(char));
TCHAR *wzLogFileName = (TCHAR *)malloc(MAX_PATH*sizeof(TCHAR));
if(!wzLogFileName || !szLogFileName)
{
if(szLogFileName) free(szLogFileName);
if(wzLogFileName) free(wzLogFileName);
}
else
{
memset(wzLogFileName,0,MAX_PATH*sizeof(TCHAR));
GetModuleFileName(NULL,wzLogFileName,MAX_PATH);
_tcsrchr(wzLogFileName,'.')[1]='\0';
_tcscat(wzLogFileName,TEXT("log"));
wcstombs(szLogFileName,wzLogFileName,MAX_PATH);
free(wzLogFileName);
FILE *fp=fopen(szLogFileName,"a");
free(szLogFileName);
if(fp!=NULL)
{
va_list va;
va_start(va, str);
vprintf(str, va);
vfprintf(fp, str, va);
va_end(va);
fclose(fp);
return TRUE;
}
}
return FALSE;
}