Problem with ListView API : LVM_ISERTITEM
-
"Hi I'm developing dll which will do some changing stuff with ListView. I have a funny problem I want to change value of iImage in a LV_ITEM according to pszText value. Problem occurs when I want to test value of pszText, exception ouccrs Access Violation 0xC0000005 :(. But I'm testing if pitem and pitem->pszText are not null even if I tryed to use strdup(pitem->pszText) the same exception occurs. There is no problem when I tryed to change value of iItem. Is is somehow connected witch injection dll into some application ?? and its address space ?? "
(WNDPROC) gfnListProc; //in some previous called function gfnListProc = (WNDPROC)SetWindowLong(listview, GWL_WNDPROC,(LONG)ListProc); __declspec(dllexport) LRESULT CALLBACK ListProc(HWND hwnd, UINT uiMsg,WPARAM wParam, LPARAM lParam) { switch (uiMsg) { case LVM_INSERTITEM: { LV_ITEM FAR* pitem = (LV_ITEM FAR*) lParam; if(pitem && pitem->pszText) MessageBox(0, pitem->pszText,":-)",MB_OK); break; } } return CallWindowProc(gfnListProc, hwnd, uiMsg, wParam, lParam); } //from commctr.h typedef struct tagLVITEMW { UINT mask; int iItem; int iSubItem; UINT state; UINT stateMask; LPWSTR pszText; int cchTextMax; int iImage; LPARAM lParam; #if (_WIN32_IE >= 0x0300) int iIndent; #endif } LVITEMW, FAR* LPLVITEMW; #define ListView_InsertItem(hwnd, pitem) \ (int)SNDMSG((hwnd), LVM_INSERTITEM, 0, (LPARAM)(const LV_ITEM FAR*)(pitem))
Thaks for reading that stuff :-) Pain is a weakness living the body -
"Hi I'm developing dll which will do some changing stuff with ListView. I have a funny problem I want to change value of iImage in a LV_ITEM according to pszText value. Problem occurs when I want to test value of pszText, exception ouccrs Access Violation 0xC0000005 :(. But I'm testing if pitem and pitem->pszText are not null even if I tryed to use strdup(pitem->pszText) the same exception occurs. There is no problem when I tryed to change value of iItem. Is is somehow connected witch injection dll into some application ?? and its address space ?? "
(WNDPROC) gfnListProc; //in some previous called function gfnListProc = (WNDPROC)SetWindowLong(listview, GWL_WNDPROC,(LONG)ListProc); __declspec(dllexport) LRESULT CALLBACK ListProc(HWND hwnd, UINT uiMsg,WPARAM wParam, LPARAM lParam) { switch (uiMsg) { case LVM_INSERTITEM: { LV_ITEM FAR* pitem = (LV_ITEM FAR*) lParam; if(pitem && pitem->pszText) MessageBox(0, pitem->pszText,":-)",MB_OK); break; } } return CallWindowProc(gfnListProc, hwnd, uiMsg, wParam, lParam); } //from commctr.h typedef struct tagLVITEMW { UINT mask; int iItem; int iSubItem; UINT state; UINT stateMask; LPWSTR pszText; int cchTextMax; int iImage; LPARAM lParam; #if (_WIN32_IE >= 0x0300) int iIndent; #endif } LVITEMW, FAR* LPLVITEMW; #define ListView_InsertItem(hwnd, pitem) \ (int)SNDMSG((hwnd), LVM_INSERTITEM, 0, (LPARAM)(const LV_ITEM FAR*)(pitem))
Thaks for reading that stuff :-) Pain is a weakness living the bodyHi, Are you sure that lParam is pointing to a valid LV_ITEM structure? Cheers, Andy
-
Hi, Are you sure that lParam is pointing to a valid LV_ITEM structure? Cheers, Andy
-
I'm pretty sure because listview is a HWND of list control and its valid Pain is a weakness living the body
Check that
mask
member containsLVIF_TEXT
This flag indicates that thepszText
member contains a valid address. If the flag is not set, the member could contain any "address". Also, check thatcchTextMax
member is not zero. (not really required) Bikram Singh -
Check that
mask
member containsLVIF_TEXT
This flag indicates that thepszText
member contains a valid address. If the flag is not set, the member could contain any "address". Also, check thatcchTextMax
member is not zero. (not really required) Bikram Singhthis pice of code doesn't work :(
case LVM_INSERTITEM: { LV_ITEM FAR* pitem = (LV_ITEM FAR*) lParam; if(!pitem && !pitem->pszText) break; if( pitem->mask & LVIF_TEXT == LVIF_TEXT && pitem->cchTextMax>0) { MessageBox(okno,pitem->pszText,":-)",MB_OK); } break;
any other ideas :confused: :mad::mad: Pain is a weakness living the body -
this pice of code doesn't work :(
case LVM_INSERTITEM: { LV_ITEM FAR* pitem = (LV_ITEM FAR*) lParam; if(!pitem && !pitem->pszText) break; if( pitem->mask & LVIF_TEXT == LVIF_TEXT && pitem->cchTextMax>0) { MessageBox(okno,pitem->pszText,":-)",MB_OK); } break;
any other ideas :confused: :mad::mad: Pain is a weakness living the bodyTry using brackets to delimit each expression you are testing in the
if
statement. Bikram Singh -
this pice of code doesn't work :(
case LVM_INSERTITEM: { LV_ITEM FAR* pitem = (LV_ITEM FAR*) lParam; if(!pitem && !pitem->pszText) break; if( pitem->mask & LVIF_TEXT == LVIF_TEXT && pitem->cchTextMax>0) { MessageBox(okno,pitem->pszText,":-)",MB_OK); } break;
any other ideas :confused: :mad::mad: Pain is a weakness living the body -
What happens if pitem != NULL and pitem->pszText = NULL? (Hint: It wont break) I would do the test: if(pitem && pitem->pszText) { // Do the dance... } Papa while (TRUE) Papa.WillLove ( Bebe ) ;
Not working hmmm hardcore hehe. Im testing changing iImage value according to iItem and it seems to be good if I know sequence of adding apriori, which will require some more coding. Anyway its really strage stuff isn't it :confused: Pain is a weakness living the body
-
Not working hmmm hardcore hehe. Im testing changing iImage value according to iItem and it seems to be good if I know sequence of adding apriori, which will require some more coding. Anyway its really strage stuff isn't it :confused: Pain is a weakness living the body
-
Try this case LVM_INSERTITEM: { LPLVITEM pitem = (LPLVITEM) lParam; if(pitem && pitem->pszText) { if( ((pitem->mask & LVIF_TEXT) == LVIF_TEXT)) { MessageBox(okno,pitem->pszText,"",MB_OK); } } break; Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
Not working. Plese remind me next time do not take a project for windows. Pain is a weakness living the body
-
Not working. Plese remind me next time do not take a project for windows. Pain is a weakness living the body
-
What happens if pitem != NULL and pitem->pszText = NULL? (Hint: It wont break) I would do the test: if(pitem && pitem->pszText) { // Do the dance... } Papa while (TRUE) Papa.WillLove ( Bebe ) ;
I would do:
if(pitem) { if(pitem->pszText) { // Do the dance... } }
Bikram Singh -
-
I would do:
if(pitem) { if(pitem->pszText) { // Do the dance... } }
Bikram Singhnot working too i think this not valid pointer beacuse its not the same address space I had the similar problem some time ago when i wannted to send some char * as wparam or lparam using SendMessage. I had to use WM_COPYDATA then char * goes thru kernel memory and pointer is valid:confused: Pain is a weakness living the body