The only working fix is to undef ATLTRACE under _DEBUG macro and implement trace by yourself. Guys at Microsoft recommended the same.
The solution looks like this:
#ifdef _DEBUG
#ifdef ATLTRACE
#undef ATLTRACE
#undef ATLTRACE2
#define ATLTRACE CustomTrace
#define ATLTRACE2 ATLTRACE
#endif // ATLTRACE
#endif // _DEBUG
with the following CustomTraces:
void CustomTrace(const wchar_t* format, ...)
{
const int TraceBufferSize = 1024;
wchar_t buffer[TraceBufferSize];
va_list argptr; va_start(argptr, format);
vswprintf_s(buffer, format, argptr);
va_end(argptr);
::OutputDebugString(buffer);
}
void CustomTrace(int dwCategory, int line, const wchar_t* format, ...)
{
va_list argptr; va_start(argptr, format);
CustomTrace(format, argptr);
va_end(argptr);
}