Getting lParam from a list view item.

This is a discussion on Getting lParam from a list view item. within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to get the pzsText and lParam variables out of a list view item. Code: //declaration of LVITEM struct ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    Getting lParam from a list view item.

    I'm trying to get the pzsText and lParam variables out of a list view item.

    Code:
    //declaration of LVITEM struct
    	LVITEM lvit;
    	ZeroMemory(&lvit, sizeof(lvit));
    	lvit.mask=LVIF_TEXT|LVIF_PARAM; //I want to get the text and lParam of the item
    	lvit.iSubItem=2; //from the 3rd column
    	lvit.cchTextMax=20;
    	lvit.pszText="";
    
    
    	for(int iteration=0; iteration<atoi(iterations); iteration++)
    	{
    
    		for(int i=0; i<ListView_GetItemCount(hwnd_ListView); i++)
    		{
    			
    			lvit.iItem=i; //item
    			ListView_GetItem(hwnd_ListView, &lvit); //This line fails
    
    		}
    
    	}
    When it reaches the failing line, the debugger shows the following message:

    Unhandled exception at 0x7c80a268 in PDS.exe: 0xC0000005: Access violation writing location 0x00448e16.

    I couldn't find a function which directly gets lParam, so I tried with ListView_GetItem()

    I'm really stuck here, thanks for any help.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How about if you allocate some memory for your pszText instead of setting it to "" - the latter makes it point to an empty string that is non-writable, and the address you are seeing the failure at indicates a non-writable memory location [of course, not guaranteed, it could be bad in some other way, but the address isn't at the end of a page, so that's not what's bad with it].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Thank you! That helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 07:16 PM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  3. Linked list pointer error
    By pattop in forum C Programming
    Replies: 1
    Last Post: 05-18-2004, 04:30 PM
  4. c++ program
    By a_a in forum C++ Programming
    Replies: 22
    Last Post: 06-02-2003, 08:46 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21