I went a different route -- I chose to edit the output like this (the message only gets shorter, so no allocation required):
#ifdef _DEBUG
static int __cdecl crtReportHookW(int nReportType, wchar_t* wszMsg, int* pnRet)
{
const wchar_t wszTrace[] = L"atlTraceGeneral - ";
const int ccTrace = _countof(wszTrace) - 1; // exclude L'\0'
if (nReportType == _CRT_WARN)
{
wchar_t* pwsz = wcsstr(wszMsg, wszTrace);
if (pwsz != nullptr)
{
int ccBuf = wcslen(pwsz) + 1; // remaining buffer size (include L'\0')
wmemmove_s(pwsz, ccBuf, &pwsz[ccTrace], ccBuf - ccTrace);
}
}
return FALSE; // always keep processing
}
#endif
And in the CWinApp-derived constructor:
#ifdef _DEBUG
_CrtSetReportHookW2(_CRT_RPTHOOK_INSTALL, crtReportHookW);
#endif
and CWinApp-derived destructor:
#ifdef _DEBUG
_CrtSetReportHookW2(_CRT_RPTHOOK_REMOVE, crtReportHookW);
#endif
For some reason, both the MCBS and wide-character versions of the hook are called with the same message, so only the wide-character hook is necessary even in an MBCS app.
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\AtlTraceTool8.exe
Presumably, VS 2013 has it there as well. It can also be started from IDE, from menu Tools. – AbacusAtlTraceXxx
functions. – Abacus