Extended Trace Macros for Win32 | CodeGuru

Extended Trace Macros for Win32

. Click here for larger image Overview 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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 6, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

.




Click here for larger image

Overview

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.

Usage

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

Macros

  • EXTENDEDTRACEINITIALIZE( IniSymbolPath )

    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.

  • EXTENDEDTRACEUNINITIALIZE()

    Frees up the symbol information.

  • SRCLINKTRACECUSTOM( Msg, File, Line)

    Write a message(Msg) to the Output Window with a link to File(Line)

  • SRCLINKTRACE( Msg )

    Write a message(Msg) to the Output Window with a link to its source code.

  • FNPARAMTRACE()

    Write the function prototype with parameters to the Output Window. You can call this function
    anytime in a function.

  • STACKTRACEMSG( Msg ),
    STACKTRACE(),
    THREADSTACKTRACEMSG( hThread, Msg ),
    THREADSTACKTRACE( hThread )

    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.

Advertisement

Example Usage

#include "ExtendedTrace.h"

void g ( LPTSTR )
{
	// Dumps the actual call stack
	STACKTRACE();
}

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

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

	// Initializes the symbol files
	EXTENDEDTRACEINITIALIZE( NULL );

	// 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
	EXTENDEDTRACEUNINITIALIZE();

	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).

Downloads

Download source code and demo – 7 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.