Standalone Tracer Window

What Tracer Is

Tracer is a simple standalone tool that displays useful information for testing/debugging MFC applications. Initially, I made this tool to make programmers' life easier when tracing complex workflows and seeing the long dynamic-built SQL queries. It proved to be much more useful and I extended its using even for intermediary release versions of applications intended to be tested at the client. That saved a lot of time in reporting/finding/fixing troubles that occurred.

Its main advantages are:

  • Allows you to see messages easier than in the 'Output' window of Visual Studio. Also, it's easier than looking in log files.
  • Does not require Debug mode as for the 'Output' window. It can be used in any type of build configuration (either Debug or Release) and can be easily enabled/disabled by declaring or not a preprocessor constant (USE_TRACER).
  • Each type of message—'general debug info', 'SQL statement', and 'error'—is displayed with a different color.
  • You can filter the type of messages to be displayed. For example, you can choose to display only the 'error' messages.
  • It displays additional info for each message, such as source file name, line number, and timestamp.
  • Its contents can be saved in a file.

How It Looks

As shown in the figure above, it is an SDI application that uses a Rich Edit view. Besides the standard menu items/toolbar buttons, it has a few additional ones to toggle always on top and to filter message types.

How It Works

It simply handles WM_COPYDATA message that is one way to pass data between processes. The COPYDATASTRUCT sent with WM_COPYDATA contains the string to be displayed and the message type.

To allow your application to send messages to Tracer, you have to link it with TraceSender.DLL, which effectively searches for the Tracer window and sends to it WM_COPYDATA. See the source code for more implementation details.

Using Tracer with Your Application

  • Include "TraceSender.h".
  • Link your application with TraceSender.lib using #pragma comment(lib,...); for example:
  • #ifdef USE_TRACER
       #pragma comment(lib,_T("\\MyProject\\lib/TraceSender.lib"))
    #endif USE_TRACER
  • Add the USE_TRACER constant to "Project Settings/C/C++/Preprocessor definitions".
  • Within your application, call the macros defined in "TraceSender.h" as, for example, DEBUG_TRACE (see the demo application, demo.exe, for more details).
  • Be sure that TraceSender.dll is in your application folder.
  • Launch Tracer.exe, launch your application, and... enjoy.

Demo Application

It's a simple application having a few dummy functions intended just to demonstrate the use of the DEBUG_TRACE, SQL_TRACE, and ERROR_TRACE macros. Below is a sample code snippet.

void CMainFrame::OnTestSql()
   // ...
      CDemoDbAccess db;
      // SQL_TRACE is called from db.ExecuteSQL
   catch(LPCTSTR pszDemoException)
void CDemoDbAccess::ExecuteSQL(LPCTSTR pszSQL)
   // ... this is just an example; may be any other error here ...
   throw(_T("You have an error in SQL statement at line 9."));
   // ...

Final Notes

If, let's say, for a stable considered version of your application, you don't need tracing anymore, you can simply remove USE_TRACER from the preprocessor definitions (or create a new build configuration with no USE_TRACER constant). That way, the TraceSender macros will be ignored, and will no more affect the application speed/size performance.

The article describes how to use Tracer for an MFC application made with VC++ 6.0. However, I think there is not any problem using it in newer versions of VC++.

About the Author

Ovidiu Cucu

Graduated at "Gh. Asachi" Technical University - Iasi, Romania. Programming in C++ using Microsoft technologies since 1995. Microsoft MVP awardee since 2006. Moderator and article reviewer at, the number one developer site. Co-founder of, a website dedicated to Romanian C++ developers.



  • Free code

    Posted by softhor on 12/15/2005 10:23am

    Hi Ovidius, firstly I want to thank you for this useful tool. Two little questions: Is this tool royalty free? Can I use in in my commercial programs? Thanks a lot, Massimo.

    • Yes.

      Posted by ovidiucucu on 12/16/2005 10:47am

      Of course.

      Best regards

      PS. Just if sometime you'll meet me, the using of the Tracer may cost you a beer. ;-)

  • Related API

    Posted by Clearcode on 12/09/2005 06:32am

    You can use the OutputDebugString API in your app and if there is a debugger attached it will recieve the trace message...

    • Yes, of course...

      Posted by ovidiucucu on 12/12/2005 10:36am

      ...but that is a quite different stuff.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date