Click here to Skip to main content
Click here to Skip to main content

Tagged as

zTrace debugging utility

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

Introduction  

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. 

Background

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

History  

This is version 2.01, from december 05, 2013.

License

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

Share

About the Author

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

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 8 Dec 2013
Article Copyright 2013 by zapsolution
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid