There is a memory allocation error in SendUnicodeToClipboard causing a GPF in zTrace 3.01.
Here is the fix to use
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);
}
}
}
}
}