Stupid *ptr problems
Ok, I admit it, I should know how to do this and I THOUGHT I did...
(seems like I've done this a 1000 times in my past) so being a little
rusty I must be missing something:
I am updating an old program and it uses GlobalAlloc() I am expanding
a block of memory to write structure of pointers to what should end up
as an array of pointers.
Everything seems to be loading fine but when I go to populate a
ListView with the data it mostly comes out as garbage... here's the
code snippets.
// * the structure definition
typedef struct {
LPSTR pszStartDate;
LPSTR pszStartTime;
LPSTR pszEndDate;
LPSTR pszEndTime;
LPSTR pszSystem;
LPSTR pszStatus;
LPSTR pszTaskName;
LPSTR pszTaskDesc;
} QUERYLOG, *PQUERYLOG;
// * This is called during the ODBC query, the returns are
// * checked and the data is valid
// * append the new record onto the array
pQueryLog = (PQUERYLOG)GlobalLock(hMem);
nCnt = (int)(GlobalSize(hMem)/sizeof(QUERYLOG));
nCnt--; // zero based array
// * we have the memory, now copy the task.
pQueryLog[nCnt].pszStartDate = _strdup(szStartDate);
pQueryLog[nCnt].pszStartTime = _strdup(szStartTime);
pQueryLog[nCnt].pszEndDate = _strdup(szStopDate);
pQueryLog[nCnt].pszEndTime = _strdup(szStopTime);
pQueryLog[nCnt].pszSystem = _strdup(szSystem);
pQueryLog[nCnt].pszStatus = _strdup("6");
pQueryLog[nCnt].pszTaskName = _strdup(szTaskName);
pQueryLog[nCnt].pszTaskDesc = _strdup(szTaskDesc);
GlobalUnlock(hMem);
// * To use the data I do this:
pQueryLog = GlobalLock(hQueryMem);
nRecCnt = (int)(GlobalSize(hQueryMem)/sizeof(QUERYLOG));
// * Insert records into ListView
hWndLV = GetDlgItem(hWndDlg, LV_HISTORY);
for(i=0; i <= nRecCnt; i++)
{
memset(&lvItem,0,sizeof(lvItem));
lvItem.mask = LVIF_TEXT;
lvItem.cchTextMax = 12;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText = pQueryLog[nCnt].pszStartDate;
SendMessage(hWndLV,LVM_INSERTITEM,0,(LPARAM)&lvItem);
memset(&lvItem,0,sizeof(lvItem));
lvItem.mask = LVIF_TEXT;
lvItem.cchTextMax = 12;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText = pQueryLog[nCnt].pszStartTime;
SendMessage(hWndLV,LVM_SETITEM,0,(LPARAM)&lvItem);
memset(&lvItem,0,sizeof(lvItem));
lvItem.mask = LVIF_TEXT;
lvItem.cchTextMax = 12;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText = pQueryLog[nCnt].pszEndDate;
SendMessage(hWndLV,LVM_SETITEM,0,(LPARAM)&lvItem);
[snip - etc, etc,]
}
I have also tried saving the data as
pQueryLog->pszStartDate;
And incrementing pQuerLog++ in the for loop. The data displays the
exact same way regardless of how I save or reference the data... I get
garbage!!
Please help!
Thanks,
Phil
===============================================
half frog half prince at oohay dot com
===============================================