Extended Trace Macros for Win32


Click here for larger image


Extended Trace is a collection of a lot of useful traces for Win32, such as:
  • TRACE(...) implementation for Win32.
  • Messages with source code links. Just double click on the message in the Output Window, and jump to the source code.
  • Function parameters. Are you wonder what parameters your function was called with? Just call a simple macro, and will trace yor function prototype with the actual parameter values to the Output Window.
  • Call stack information. You can trace the call stack with function prototypes and parameters' values. Just like the Visual Studio Call Stack window, but this is in run-time.


Add the ExtendedTrace.cpp to your project, and include ExtendedTrace.h to your source file.



    Initialize the symbol information. "IniSymbolPath" is the search path for the symbol files. The built-in path is ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;". IniSymbolPath will be added to the built-in path. IniSymbolPath can be NULL.

    Frees up the symbol information.
    Write a message(Msg) to the Output Window with a link to File(Line)
    Write a message(Msg) to the Output Window with a link to its source code.
    Write the function prototype with parameters to the Output Window. You can call this function anytime in a function.
    Dumps the call stack with function prototypes and the parameters' values to the Output Window. The call stack elements dumped with source code links, so you can jump directly to them.
  • TRACEF(...)
    Same as the MFC TRACE(...)
Note: If you're using only TRACEF(...) or SRCLINKTRACExxx(...) macros, you don't need EXTENDEDTRACEINITIALIZE(...)/EXTENDEDTRACEUNINITIALIZE.

Example Usage

#include "ExtendedTrace.h"

void g ( LPTSTR )
	// Dumps the actual call stack

void f( int, int, int )
	// What parameters was this function called with?
	g( NULL );

int main( int, char** )
	// Just like the TRACE(...) in MFC
	TRACEF( _T("Application started at %d\n"), clock() );

	// Initializes the symbol files

	// Trace message with a link to this line in the source code
	SRCLINKTRACE( _T("I'm calling f(...)\n") );

	f( 1, 2, 3);

	// Cleaning up

	TRACEF( _T("Application ended at %d\n"), clock() );

	return 0;
The output in the Output Window...
Application started at 578
Loaded 'D:\WINNT\system32\dbghelp.dll', no matching symbolic information found.
c:\temp\magictrace\main.cpp(28) : I'm calling f(...)
Function info(thread=0x36C) : void f(int=0x00000001,int=0x00000002,int=0x00000003)
Call stack info(thread=0x36C) : 
     c:\temp\magictrace\main.cpp(12) : void g(char *=0x00000000)
     c:\temp\magictrace\main.cpp(19) : void f(int=0x00000001,int=0x00000002,int=0x00000003)
     c:\temp\magictrace\main.cpp(30) : main(int=0x00000001,TCHAR * *=0x00522C88)
     crtexe.c(338) : mainCRTStartup()
     KERNEL32!0x77E87903 : SetUnhandledExceptionFilter
Application ended at 1171
The thread 0x36C has exited with code 0 (0x0).


Download source code and demo - 7 Kb


  • Try this tool, It's not need modify source.

    Posted by pengch on 03/31/2004 02:26am

    Try this tool, It's not need modify source.
    It's also support stack trace in release version of the exe and dll.

    Try it now. Auto Debug Tool

  • Excellent Utility!

    Posted by Legacy on 11/04/2002 12:00am

    Originally posted by: Henri Manson

    Immediately usable in the Pingus game project

  • I want the stack trace in Release version of the exe

    Posted by Legacy on 09/20/2001 12:00am

    Originally posted by: Mustufa Taj


    I want the stack trace in the Release version of the product.
    I removed the # if(defined) DEBUG statements and got a stack trace as follows:


    This is because the symbol file might not be available for Release versions.

    Do you have any way by which this can work in release mode.


  • Nice code, but SymInitialize fails..

    Posted by Legacy on 03/16/2001 12:00am

    Originally posted by: Lee Wilson

    I'm using Windows 98SE and I've upgraded ImageHlp.dll to version 5.00.1678.1. However, when I do EXTENDEDTRACEINITIALIZE with a NULL, my path set, or even passing it "C:\\" as a path(which should theoretically find ALL symbols since the docs say that this is simply a root path to search), SymInitialize fails. Doing a GetLastError only tells me that "The specified module could not be found".

    I've tried other stack trace code out there, but it all comes down to SymInitialize failing. Any ideas as to why SymInitialize would fail?

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

Top White Papers and Webcasts

  • 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 …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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