obtaining listview data efficiently...

This is a discussion on obtaining listview data efficiently... within the Windows Programming forums, part of the Platform Specific Boards category; hey all, I am currently writing a function to obtain all of a listview control's data and store it into ...

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    obtaining listview data efficiently...

    hey all,
    I am currently writing a function to obtain all of a listview control's data and store it into a multidimensional array of pointers. the reason for this is simply because it makes it easier for me to access each string of listview data.

    I have a listview (LVS_REPORT) with 4 columns. here is how I am declaring my multidimensional array of pointers:

    Code:
    char *szListData[50][4];
    where 50 is the max number of rows, and 4 is the number of columns. now here is how I am attempting to obtain the data:

    Code:
    for(i = 0; i < nListNum; i++)
         for(j = 0; j < 4; j++)
    	 ListView_GetItemText(hwndList, i, j, szListData[i][j], _MAX_FNAME);
    what am I doing wrong here? nListNum is the number of items listed in the listview, which is a number less than or equal to 50.

    whenever I attempt to print anything from szListData (just to see if it worked), Windows throws up an error message saying that the application needs to be closed.

    could anyone please tell me what I am doing wrong here?

    any help is greatly appreciated .
    Last edited by Bleech; 10-15-2006 at 10:32 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    It is a multidimensional array which has 50 "rows".
    Now, it has 4 "columns". And every column contains... unallocated memory or.... a single character?
    Wouldn't this make more sense:
    Code:
    char szListData[50][4][_MAX_FNAME];
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    thanks max, I was using an array of pointers because I figured that way I could only allocate the size of each piece of data (without having to set a size to be allocated), but doing it that way would involve some complex allocation routine (getting the length of each piece of data and allocating each pointer by that). when I change this:

    Code:
    char *szListData[50][4];
    to this:

    Code:
    char szListData[50][4][_MAX_FNAME];
    my little bit of debug code to print from the array prints just how I wanted .

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by sl34k
    but doing it that way would involve some complex allocation routine (getting the length of each piece of data and allocating each pointer by that).
    You wouldn't really need a complex allocation routine, just one where you had a large buffer, then strdup() the string to the location in the array. Just don't forget to free() the array elements if you reassign (and before you return).

  5. #5
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    thanks Kennedy, but doing it with an array seems to work fine, I just looked at the decription of strdup, and I can't really be bothered doing it that way .

    but I have ran into another pointer related problem .

    I am starting to understand pointers alot better now, all this experience is surely helping. here is what I am doing:

    Code:
    p = PathFindFileName(szListData[0][0]);
    
    strcpy(pfile->name, p);
    
    MessageBox(NULL, pfile->name, NULL, MB_OK);
    when I compile, it compiles 0 errors, 0 warnings, but when I run it, I get the error from Windows saying that the application needs to be closed.

    p is declared:

    Code:
    char *p = "";
    name is declared:

    Code:
    char name[_MAX_FNAME];
    when I try this:

    Code:
    p = PathFindFileName(szListData[0][0]);
    
    MessageBox(NULL, p, NULL, MB_OK);
    it prints the filename successfully without any problems.

    can anyone please tell me why this is happening here? I really can't figure this one out, name is an array that obviously has _MAX_FNAME bytes allocated.
    Last edited by Bleech; 10-17-2006 at 05:08 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 02:27 AM
  2. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-27-2005, 11:59 PM
  3. Dynamic data members?
    By confusalot in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 10:15 AM
  4. Obtaining data through RS-232 port...
    By johny780 in forum C Programming
    Replies: 9
    Last Post: 10-08-2003, 10:38 AM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 02:22 PM

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