Click here to Skip to main content
Licence 
First Posted 12 Jul 2005
Views 18,362
Bookmarked 12 times

Supressing TRACE calls

By | 12 Jul 2005 | Article
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

About the Author

Cristian Amarie

Team Leader
BitDefender
Romania Romania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralWhy not... PinmemberHans Dietrich7:15 12 Jul '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.5.120517.1 | Last Updated 12 Jul 2005
Article Copyright 2005 by Cristian Amarie
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid