mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-04-25 08:06:30 +00:00
[idd] common: still print the message if FormatMsg failed
This commit is contained in:
parent
d839a45d0b
commit
86de1c9ac6
@ -82,7 +82,7 @@ void CDebug::Init(const char * name)
|
||||
m_stream = std::move(stream);
|
||||
}
|
||||
|
||||
void CDebug::Log(CDebug::Level level, const char * function, int line, const char * fmt, ...)
|
||||
void CDebug::Log_va(CDebug::Level level, const char* function, int line, const char* fmt, va_list args)
|
||||
{
|
||||
if (level < 0 || level >= LEVEL_MAX)
|
||||
level = LEVEL_NONE;
|
||||
@ -90,9 +90,6 @@ void CDebug::Log(CDebug::Level level, const char * function, int line, const cha
|
||||
static const char* fmtTemplate = "[%s] %40s:%-4d | ";
|
||||
const char* levelStr = m_levelStr[level];
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
int length = 0;
|
||||
length = _scprintf(fmtTemplate, levelStr, function, line);
|
||||
length += _vscprintf(fmt, args);
|
||||
@ -102,10 +99,7 @@ void CDebug::Log(CDebug::Level level, const char * function, int line, const cha
|
||||
PCHAR buffer;
|
||||
buffer = (PCHAR)_malloca(length);
|
||||
if (!buffer)
|
||||
{
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Populate the buffer with the contents of the format string. */
|
||||
StringCbPrintfA(buffer, length, fmtTemplate, levelStr, function, line);
|
||||
@ -113,16 +107,23 @@ void CDebug::Log(CDebug::Level level, const char * function, int line, const cha
|
||||
size_t offset = 0;
|
||||
StringCbLengthA(buffer, length, &offset);
|
||||
StringCbVPrintfA(&buffer[offset], length - offset, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
buffer[length-2] = '\n';
|
||||
buffer[length-1] = '\0';
|
||||
buffer[length - 2] = '\n';
|
||||
buffer[length - 1] = '\0';
|
||||
|
||||
Write(buffer);
|
||||
|
||||
_freea(buffer);
|
||||
}
|
||||
|
||||
void CDebug::Log(CDebug::Level level, const char * function, int line, const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
Log_va(level, function, line, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void CDebug::LogHR(CDebug::Level level, HRESULT hr, const char * function, int line, const char * fmt, ...)
|
||||
{
|
||||
if (level < 0 || level >= LEVEL_MAX)
|
||||
@ -140,6 +141,11 @@ void CDebug::LogHR(CDebug::Level level, HRESULT hr, const char * function, int l
|
||||
))
|
||||
{
|
||||
DEBUG_INFO("FormatMessage failed with code 0x%08x", GetLastError());
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
Log_va(level, function, line, fmt, args);
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ class CDebug
|
||||
};
|
||||
|
||||
void Init(const char * name);
|
||||
void Log_va(CDebug::Level level, const char* function, int line, const char* fmt, va_list args);
|
||||
void Log(CDebug::Level level, const char * function, int line, const char * fmt, ...);
|
||||
void LogHR(CDebug::Level level, HRESULT hr, const char* function, int line, const char* fmt, ...);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user