Click here to Skip to main content
13,146,934 members (58,894 online)
Click here to Skip to main content
Add your own
alternative version

Stats

8K views
168 downloads
9 bookmarked
Posted 20 Apr 2017

zTrace 3 (for 64-bit only)

, 27 Apr 2017
Rate this:
Please Sign up or sign in to vote.
Debugging utility

Introduction

This is a reworked version of the previous project posted here
https://www.codeproject.com/Articles/693260/zTrace-debugging-utility
(keep using this previous version with 32-bit applications) 

This new version is meant to be linked to debug UNICODE 64-bit applications only.

This is a Visual Studio 2017 community project, that has been highly optimized to reduce the size of the zTrace.dll down from 91 to 14 Kb.
(it is based on the same technic used to produce the tiny MBox64 OpenGL visual plugins.)

Background

The purpose of this utility is to display debugging information into a popup window tool, and/or a text file, using 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.

zTrace uses exclusively the core flat API SDK procedural style, that is the only common denominator understood by the different languages i use, and also the only way to get rid of extra dependencies.

This version is UNICODE only, there is an ANSI version written in PowerBASIC but only for 32-bit.

Using the code

There is only one API to call like this:

zTrace(L"Wide String Information")

Passing a single unicode (WCHAR) string, holding the information to display in the trace window.

Helper function, for EXPLICIT linking:

#define long_proc typedef long (__stdcall *zProc)

long zTrace(IN WCHAR* 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*);
        static zProc hProc;
        if (hProc == 0) { hProc = (zProc)GetProcAddress(hDll, "zTrace"); }
        if (hProc) { nRet = hProc(sPtr); }
    }
    return nRet;
}

Insight

The 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 for the next session.

Screen shot:

 

Compiler settings

In order to drastically reduce the size of the zTrace.dll, you must use the provided TCLib.lib and setup the Property Pages like this:


Include + Pragma

#include <windows.h>
#include "..\TCLib\Strings.cpp"

#pragma warning(disable: 4996) // remove Unsafe notifications
#pragma warning(disable: 4312) // remove warning C4312: 'type cast': conversion from 'long' to 'HMENU' of greater size</font></code>

About

You can learn more about my work, and download several C++ demo projects on my private forum
www.objreader.com

Update

04-26-2017
The ZIP file has been updated

Fix:
delete [] SelItem;
was unexpectedly missing from the case IDM_Print

Enhancement:
New menu option: "Use Unicode in zDebug.txt"
to switch between ANSI or UNICODE
in case of ANSI, a UTF-8 BOM header is now being used.
UTF-8 BOM is a sequence of bytes (EF BB BF) that allows the reader to identify a file as being encoded in UTF-8.

Thanks to Andrey Unis who reported these to me.

04-27-2017

I have merged Andrei changes into a new version, with:
further code clean up,
new font set for both the listbox window and the printer,
switched back to XP compatibility,
no more TCLib linking that has been removed.

With more features, and further code optimization, we have been able to keep the size of the 64-bit Unicode DLL at only 11 Kb...

 

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.

You may also be interested in...

Comments and Discussions

 
QuestionUpdate Pin
zapsolution26-Apr-17 4:58
memberzapsolution26-Apr-17 4:58 
QuestionSmaller and with less bugs elsewhere Pin
Member 1314381121-Apr-17 12:46
memberMember 1314381121-Apr-17 12:46 
AnswerRe: Smaller and with less bugs elsewhere Pin
zapsolution21-Apr-17 21:56
memberzapsolution21-Apr-17 21:56 
GeneralMy vote of 5 Pin
Ecodfert21-Apr-17 4:52
memberEcodfert21-Apr-17 4:52 
GeneralMy vote of 5 Pin
DanielDuval20-Apr-17 22:43
memberDanielDuval20-Apr-17 22:43 
GeneralRe: My vote of 5 Pin
zapsolution21-Apr-17 4:27
memberzapsolution21-Apr-17 4:27 

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
Web03 | 2.8.170915.1 | Last Updated 27 Apr 2017
Article Copyright 2017 by zapsolution
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid