int DbgPrintf (LPSTR sz,...)
{
static char szOutput[1024];
va_list va;
va_start(va, sz);
wvsprintf (szOutput,sz,va); /* Format the string */
va_end(va);
OutputDebugString(szOutput);
return FALSE;
}
By the way, %s or %S will deal with the wide char or ansii char string.
CRITICAL_SECTION cs_log_f;
void init_log_file()
{
InitializeCriticalSection(&cs_log_f);
}
void de_init_log_file()
{
DeleteCriticalSection(&cs_log_f);
}
void log2filew(wchar_t * format, ...)
{
EnterCriticalSection(&cs_log_f);
FILE *fOutput = NULL;
static WCHAR buffer[1024] = { 0 };
if ((fOutput = _wfopen(L"//logp.txt", L"a+b")) != NULL)
{
va_list va;
va_start(va, format);
//swprintf(buffer, format, va);
wvsprintf (buffer,format,va); /* Format the string */
va_end(va);
fwprintf(fOutput, buffer);
fwprintf(fOutput, L"/r/n");
fclose(fOutput);
}
LeaveCriticalSection(&cs_log_f);
}
void log2file(char* fmt, ...)
{
va_list ap;
static char message[1024];
HANDLE logfile;
DWORD wrote;
va_start(ap, fmt);
EnterCriticalSection(&cs_log_f);
vsprintf(message, fmt, ap);
va_end(ap);
logfile = CreateFile(L"//Temp//data.txt",
GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if (logfile!=INVALID_HANDLE_VALUE) {
SetFilePointer(logfile, 0, NULL, FILE_END);
WriteFile(logfile, message, strlen(message), &wrote, 0);
}
CloseHandle(logfile);
LeaveCriticalSection(&cs_log_f);
}