Click here to Skip to main content
13,044,115 members (82,896 online)
Click here to Skip to main content
Add your own
alternative version

Stats

22.8K views
12 bookmarked
Posted 12 Jul 2005

Supressing TRACE calls

, 12 Jul 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Cristian Amarie
Team Leader BitDefender
Romania Romania
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralWhy not... Pin
Hans Dietrich12-Jul-05 7:15
memberHans 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Jul 2005
Article Copyright 2005 by Cristian Amarie
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid