Introduction
The necessity: bloated/unnecessary/too many TRACE calls in the previously written code that disturb the debugging process.
How it works
The variable that controls the TRACE calls is afxTraceEnabled
. It is defined in the file C:\Program Files\Microsoft Visual Studio\VC98\MFC\Include\AFX.H (the default installation path of Visual C++ 6.0).
The afxTraceEnabled
flag is global, so it will affect all the TRACE calls.
#include "StdAfx.h"
#include "MyClass.h"
#ifdef _DEBUG
__declspec(dllimport) extern BOOL afxTraceEnabled;
#endif
CMyClass::CMyClass()
{
#ifdef _DEBUG
afxTraceEnabled = FALSE;
#endif
}
That is all. Here, the TRACE calls are suppressed and only the OutputDebugString
calls remain. The variable can be set/unset as and when necessary to allow or disable TRACE calls in certain sections, however this should be done by modifying the source code of all the files affected.
Another approach is to implement enable/disable of the flag in a separate file. Calling two functions, let' say __EnableTrace
and __DisableTrace
allows the implementation to be controlled in a single place, and the source code of other files can call these functions as and when necessary.