S
Simon K
When I call
---->>> SetLog("WinMain", Msg("Loading %s ...", filename)); <<---
TCHAR *Msg(TCHAR *szFormat, ...)
{
TCHAR szBuffer[1024]=""; // Large buffer for long filenames or
URLs
const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
const int LASTCHAR = NUMCHARS - 1;
// Format the input string
va_list pArgs;
va_start(pArgs, szFormat);
// Use a bounded buffer size to prevent buffer overruns. Limit
count to
// character size minus one to allow for a NULL terminating
character.
_vsntprintf(szBuffer, NUMCHARS - 1, szFormat, pArgs);
va_end(pArgs);
// Ensure that the formatted string is NULL-terminated
szBuffer[LASTCHAR] = TEXT('\0');
// Display a message box with the formatted string
return szBuffer;
}
void SetLog(TCHAR *ID, TCHAR *szMsg)
{<-----------------------------------------------------szMsg =
szBuffer (of Msg(..))
TCHAR str[BUFSIZE]=""; <------------------------- szMsg reseted!
WHY!?!!!??
TCHAR gt1[BUFSIZE]="", gt2[BUFSIZE]="";
struct tm *newtime;
time_t aclock;
time( &aclock ); // Get time in seconds
newtime = localtime( &aclock ); // Convert time to struct tm form
_tcscpy(gt1, _tasctime(newtime));
_tcsncat(gt2, gt1, _tcslen(gt1)-1);
wsprintf(str, "[%s]%s : %s \n", gt2, ID, szMsg);
AppendText(ghSttEM, str);
FILE *stream = fopen("dc.log","a+");
_ftprintf(stream, str);
fclose(stream);
}
I go through SetLog, it first calls Msg(...) in order to display in
format.
As i debug step by step, I found out some weird problems...
I indicated the problem on the source, can someone tell me what's
going wrong with this code?
---->>> SetLog("WinMain", Msg("Loading %s ...", filename)); <<---
TCHAR *Msg(TCHAR *szFormat, ...)
{
TCHAR szBuffer[1024]=""; // Large buffer for long filenames or
URLs
const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
const int LASTCHAR = NUMCHARS - 1;
// Format the input string
va_list pArgs;
va_start(pArgs, szFormat);
// Use a bounded buffer size to prevent buffer overruns. Limit
count to
// character size minus one to allow for a NULL terminating
character.
_vsntprintf(szBuffer, NUMCHARS - 1, szFormat, pArgs);
va_end(pArgs);
// Ensure that the formatted string is NULL-terminated
szBuffer[LASTCHAR] = TEXT('\0');
// Display a message box with the formatted string
return szBuffer;
}
void SetLog(TCHAR *ID, TCHAR *szMsg)
{<-----------------------------------------------------szMsg =
szBuffer (of Msg(..))
TCHAR str[BUFSIZE]=""; <------------------------- szMsg reseted!
WHY!?!!!??
TCHAR gt1[BUFSIZE]="", gt2[BUFSIZE]="";
struct tm *newtime;
time_t aclock;
time( &aclock ); // Get time in seconds
newtime = localtime( &aclock ); // Convert time to struct tm form
_tcscpy(gt1, _tasctime(newtime));
_tcsncat(gt2, gt1, _tcslen(gt1)-1);
wsprintf(str, "[%s]%s : %s \n", gt2, ID, szMsg);
AppendText(ghSttEM, str);
FILE *stream = fopen("dc.log","a+");
_ftprintf(stream, str);
fclose(stream);
}
I go through SetLog, it first calls Msg(...) in order to display in
format.
As i debug step by step, I found out some weird problems...
I indicated the problem on the source, can someone tell me what's
going wrong with this code?