Getting rid of the atlTraceGeneral category shown in ATLTRACE output

After upgrading to VS2013, I started receiving all my ATLTRACE2 messages in the format "(): atlTraceGeneral - My output".

eg.

ATLTRACE(_T("This is my data: %d\n"), 124); 

... shown as

 dllmain.cpp(1121) : atlTraceGeneral - This is my data: 124 

I do not need additional information. Is there a way to go back to the previous format so that the output is just

 This is my data: 124 
+6
source share
2 answers

The only working fix is ​​to undef ATLTRACE in the _DEBUG macro and implement tracing yourself. The guys from 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 settings:

 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); } 
+7
source

I went the other way - I decided to edit the output like this (the message gets shorter, so no selection is 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 constructor of CWinApp:

 #ifdef _DEBUG _CrtSetReportHookW2(_CRT_RPTHOOK_INSTALL, crtReportHookW); #endif 

and a destructor derived from CWinApp:

 #ifdef _DEBUG _CrtSetReportHookW2(_CRT_RPTHOOK_REMOVE, crtReportHookW); #endif 

For some reason, both MCBS and widescreen versions of the hook are called with the same message, so only a wide-angle hook is needed even in the MBCS application.

0
source

All Articles