Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC
Article

Supressing TRACE calls

Rate me:
Please Sign up or sign in to vote.
2.66/5 (9 votes)
12 Jul 2005 31.4K   12   1
How to prevent TRACE calls from appearing in the output window.

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader BitDefender
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWhy not... Pin
Hans Dietrich12-Jul-05 7:15
mentorHans Dietrich12-Jul-05 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.