Hello...

I am looking for a way to know the string length of a listview item/subitem so I can dynamically allocate memory to put it in it ?
I have searched everywhere and I really wonder if it is possible ?

Does somebody know a (even tricky) way to do this ? Having a truncated string is not enough in my case...

Thanks.
Posted on 2003-07-29 07:51:17 by JCP
Read the description of LVM_GETITEMTEXT. It returns the length of the string (in eax). You can try to send it with LV_ITEM.cchTextMax set to 1 or 0, get returned length of the string and then send the message again with rigth cchTextMax.
Posted on 2003-07-29 09:00:01 by JohnFound
Posted on 2003-07-29 09:19:28 by QvasiModo

Read the description of LVM_GETITEMTEXT. It returns the length of the string (in eax). You can try to send it with LV_ITEM.cchTextMax set to 1 or 0, get returned length of the string and then send the message again with rigth cchTextMax.


Thanks John, I tried this many times before posting here but this unfortunaly does not work.
The documentation is not clear, it is a bit unclear in the way it says the thing but if one reads more carefully :


If you send this message explicitly, it returns the number of characters in the pszText member of the LVITEM structure.


one then notices that it means the lenght of the retrieved text in pszText and not the actual one... :(
Posted on 2003-07-29 09:33:58 by JCP


Thanks Qvasimodo, but I don't think it will do the trick either :( :

In one of the threads you wrote :


Maybe you could try reading the items text with LVM_GETITEMTEXT to a buffer, say, 4k long, and check the return value, and if the buffer was completely filled increase it's size to another 4k and try again... you can keep increasing the buffer size until the whole string has been read. You can use 4k increases because it's the system granularity, so all memory blocks are a multiple of 4k (I think)...


Unfortunaly, in this case, the return value is irrelevant because my documentation states :


If you send this message explicitly, it returns the number of characters in the pszText member of the LVITEM structure.


The function won't send any information to say whether it was truncated or not... so your solution won't work... :(
Posted on 2003-07-29 09:39:45 by JCP

The function won't send any information to say whether it was truncated or not... so your solution won't work... :(


Indeed, but you do know when the string WAS NOT truncated :) . So if your buffer was not filled completely, it means you have the entire string. If not, try with a bigger buffer. If the string just happened to have the exact same size as your buffer, the worst that can happen is that you're polling twice for the same data and your buffer will be a bit larger than needed, but at least you'll be sure you've got the entire string.
Posted on 2003-07-29 10:07:04 by QvasiModo
That's an interesting idea !

Thanks for it ! :alright:
Posted on 2003-07-29 10:17:17 by JCP