Author Topic: zTrace version 3.00  (Read 17189 times)

James Fuller

  • Newbie
  • *
  • Posts: 41
Re: zTrace version 3.00
« Reply #15 on: September 09, 2020, 04:12:13 pm »
Patrice,
   This is much easier. A bit bigger but ....
I just added a few lines to the ztrace.cpp file
I do have to close the zTrace window with the "x" instead of having the program that called it exit for it to be persistent.

James

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: zTrace version 3.00
« Reply #16 on: September 09, 2020, 09:07:52 pm »
James

GetTempath, should already have a trailing back slash, please check the value returned by the API before adding zTrace3.cfg.

Other way L"\\" should be added only if missing.

See the PathAddBackslash API
Patrice
(Always working with the latest Windows version available...)

James Fuller

  • Newbie
  • *
  • Posts: 41
Re: zTrace version 3.00
« Reply #17 on: September 09, 2020, 09:10:22 pm »
Patrice,
  I guess I'm just getting too old for coding!
Delete this topic. It was my oversight.
I thought just unloading the zTrace dll by termination of the program that called it would create/update the cfg file.
I also thought I wrote a small snippit that printed GetTempPath and it did not have a trailing "\", but on further review it does,just as you said.
Sorry to have bothered you.
James

 

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: zTrace version 3.00
« Reply #18 on: September 10, 2020, 02:27:37 pm »
James

How old are you, i think coding is good to keep our neurone at work ;)
Patrice
(Always working with the latest Windows version available...)

James Fuller

  • Newbie
  • *
  • Posts: 41
Re: zTrace version 3.00
« Reply #19 on: September 10, 2020, 04:36:42 pm »
Patrice,
  After a reboot of me (a good nights sleep) and the computers my OCD would not let me drop this. I found I'm not as bad as I previously thought.
I again used zTrace64.dll from the forum posting.
After the window popped up I right clicked and selected the create debug.txt.
After the popup menu closed I right clicked again and the create debug.txt item was checked.
I then closed the ztrace window using the red "x"
The ztrace.cfg file was created in my user temp folder but nothing was written to it. It had a size of 0
When I ran my app again and right clicked the ztrace window the create debug.txt was not checked.

I then took the ztrace 3.01 ztrace.cpp source and only added a couple of lines at the top. No change to the GetTempPath. I compiled with the attached buildit.bat file.
I replaced zTrace64.dll (3.00) from the forum with the new 3.01 (renamed 3.02 by me).

I deleted ztrace.cfg from the temp folder and repeated the above. This time the ztrace.cfg had a size of 1
and all worked as expected.

The Test_zTrace.cpp was created with BCX and is a non-unicode app that just calls zTrace through ZPRINT which is defined as:
#define ZPRINT(x) zTrace(AnsiToWide((char*)(x)))

platform:
Windows 10 64. version 2004(osbuild 19041.508)

I'm not going to beat on this anymore. I don't know why mine works and your's does not? I now have a working version.

I would like permission to include my version with an upcoming BcxAdp (BCX Application Development Platform)
All of your copyright notices and acknowledgments would be included.

Mr BCX has done a fantastic job on updating BCX. Now with a working pre-compiler meta command $PP I do not have to fork and change BCX to add more of the c++ items I want.

Thank for your patience.
Age: 72
James





Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: zTrace version 3.00
« Reply #20 on: September 10, 2020, 07:28:24 pm »
James

You are just one year older than me ;)

Obviously i can't see any difference between the 2 codes, except that i am using the Visual Studio environment, while you are using the command line.

I am using Windows 10 Professional 2004 OS version 19041.508

Yes, you have my permission to include zTrace64 with the upcoming BcxAdp.

Where are you living?


Patrice
(Always working with the latest Windows version available...)

James Fuller

  • Newbie
  • *
  • Posts: 41
Re: zTrace version 3.00
« Reply #21 on: September 10, 2020, 08:02:57 pm »
James

You are just one year older than me ;)


Where are you living?

I am here:
https://goo.gl/maps/bA97cRTi8FeZbo2Q9

James

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
SendUnicodeToClipboard
« Reply #22 on: October 23, 2021, 05:09:23 pm »
There is a memory allocation error in SendUnicodeToClipboard causing a GPF in zTrace 3.01.

Here is the fix to use

Code: [Select]
static void SendUnicodeToClipboard(HWND hWnd) {
    HWND hCtrl = GetDlgItem(hWnd, ID_LISTBOX);
    long nCount = (long)(DWORD)SendMessage(hCtrl, LB_GETCOUNT, 0L, 0L);
    if (nCount > 0) {
        long bufsize = 0;
        long *pSelItems = NULL;
        long nSelItems = (long)SendMessage(hCtrl, LB_GETSELCOUNT, 0L, 0L);
        if (nSelItems > 0) {
            nCount = 0;
            pSelItems = (long *)GlobalAlloc(GPTR, nSelItems * sizeof(long));
            if (pSelItems) {
                nCount = nSelItems;
                SendMessage(hCtrl, LB_GETSELITEMS, nSelItems, (LPARAM)pSelItems);
            }
        }

        for (long i = 0; i < nCount; i++) {
            long index = pSelItems ? pSelItems[i] : i;
            long cch = (long)SendMessage(hCtrl, LB_GETTEXTLEN, (WPARAM)index, 0L);
            if (cch > 0)
                bufsize += cch + 2;
        }

        if (bufsize > 0) {
            HGLOBAL hClipData = GlobalAlloc(GHND | GMEM_DDESHARE, (bufsize + 1) * sizeof(TCHAR));
            if (hClipData) {
                LPTSTR  buffer = (LPTSTR)GlobalLock(hClipData);
                long offset = 0;

                for (long i = 0; i < nCount; i++) {
                    long index = pSelItems ? pSelItems[i] : i;
                    long cch = (long)SendMessage(hCtrl, LB_GETTEXTLEN, (WPARAM)index, 0L);
                    if (cch > 0) {
                        if ((offset + cch + 2) > bufsize)
                            break;

                        cch = (long)SendMessage(hCtrl, LB_GETTEXT, (WPARAM)index, (LPARAM)(buffer + offset));
                        offset += cch;
                        buffer[offset++] = '\r';
                        buffer[offset++] = '\n';
                    }
                }

                buffer[bufsize] = 0;
                GlobalUnlock(hClipData);

                if (OpenClipboard(0)) {
                    EmptyClipboard();
                    SetClipboardData(CF_UNICODETEXT, hClipData);
                    CloseClipboard();
                } else {
                    GlobalFree(hClipData);
                }
            }
        }
    }
}
Patrice
(Always working with the latest Windows version available...)