Click here to Skip to main content
13,042,421 members (138,512 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


25 bookmarked
Posted 6 Dec 2013

zTrace debugging utility

, 7 Dec 2013
Rate this:
Please Sign up or sign in to vote.
This is a VS2010+ project


zTrace, is a small DLL utility to display debugging information into a popup window tool, and/or a text file.
It uses a distinct thread to work in parallel of the current application you want to debug. 


zTrace is very useful at development time to check whether a program operates properly.
It has been modeled onto the WinDev's Trace API, the original Win32 version was written in PowerBASIC.

I first wrote zTrace to debug my addon graphic DLL tools, but it works also very well with any 32-bit or 64-bit EXE.
When i took the decision to convert WinLIFT and GDImage to C++, it was the first on my list, because i couldn't develop anymore without it.

Using the code  

zTrace uses exclusively the low level API, that is the only common denominator to all the languages i use, and the only way to get rid of extra dependencies.
The source code is provided in pure SDK coding style like documented into Charles Petzold 5th edition (the SDK coder Bible).

zTrace is UNICODE based. 

Syntax to use:
zTrace(L"Wide String Information")

One single wstring, holding the information to display in the trace window.

Parameter details 

Trace window:
• The information passed as parameter is displayed on the next line of the zTrace window.
• The trace window is automatically opened when zTrace is called, by default, this window is opened at the top left corner of the screen.
• The zTrace window shuts down automatically when you close the application being debugged.

zDebug.txt report:
• Works exactly like the zTrace window, except that the information is written to a text file.
• The report is automatically created when zDebug is called, it is saved into the same folder than the debugged application.
• zDebug can be used alone or combined with zTrace (when the option is checked in the popup menu).
• zDebug is very handy when the debugged application shuts down unexpectedly or when the application as a short life duration, that won't give you enough time to read what is written in the zTrace window.
• A new fresh zDebug.txt is created each time you start a new zDebug session.

Contextual popup menu (right mouse click on the trace window):
• Use horizontal scrollbar, show or hide the horizontal scrollbar.
• Send selection to printer, print the selected lines (or the whole list when none).
• Copy selection to clipboard, copy the selected lines (or the whole list when none) to clipboard.
• Clear content, clear the content of the Trace window.
• Trace window TopMost, open the Trace window on top of all the other windows (including the windows from the other applications).
• Create zDebug.txt report, the zDebug.txt report is created into the debugged application's folder.
• Save window coordinates, store the size and position of the zTrace window into the registry when closed. Next time the window will be shown using the previous size and location. 

Screen shot: 

Helper function 

This is the helper function to put into your code to use either zTrace32.dll or zTrace64.dll 

#define long_proc typedef long (__stdcall *zProc)
long zTrace (IN wstring sPtr) {
    long nRet = 0;
    static HMODULE hDll;
    if (hDll == 0) { 
        if (sizeof(LONG_PTR) == 8 ) {
            hDll = LoadLibrary(L"zTrace64"); }
        else {
            hDll = LoadLibrary(L"zTrace32");
    if (hDll) {
        long_proc (WCHAR*);
        zProc hProc = (zProc) GetProcAddress(hDll, "zTrace");
        if (hProc) { nRet = hProc((WCHAR*) sPtr.c_str()); }
    return nRet;
If for any reason the ZIP file is missing from this post, you can download the full VS2010 source code of the project here.

SDK programming  

I am a low level Windows SDK programmer writing graphic addons and multimedia applications.
You can learn more about my work, and download several C++ demo projects here.

Note: On the same link you will find the Exif project, that is using zTrace to display the data from jpeg image files (using GDImage.dll).


This is version 2.01, from december 05, 2013.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer zapsolution
France France
I am a low level SDK programmer, focusing mainly on graphic imaging and multimedia applications.
I am using several languages, including C, C++, PowerBASIC, WinDev.
I wrote also a few demos in C#, but i never used DotNET in real code production.

You may also be interested in...

Comments and Discussions

QuestionIs FreeLibrary necessary? Pin
YDLU28-Apr-17 11:48
memberYDLU28-Apr-17 11:48 
AnswerRe: Is FreeLibrary necessary? Pin
zapsolution28-Apr-17 22:28
memberzapsolution28-Apr-17 22:28 

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 8 Dec 2013
Article Copyright 2013 by zapsolution
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid