Hi,
I want to fill a ListCtrl in C++ with OwnerData.
I am managing OnGetDispInfo() to provide the text information to display,
but my question is, who manages the memory in the item.pszText ?
I tryed to do in 2 different ways, and they both seem to work, or at least
the text is displayed:
Example 1-
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
if (pDispInfo->item.mask & LVIF_TEXT)
{
CString Message = "HELLO";
lstrcpy(pDispInfo->item.pszText, Message);
}
Example 2-
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
if (pDispInfo->item.mask & LVIF_TEXT)
{
TCHAR *Message;
Message=MyGetTextBuffer(); //This returns a buffer with the text to display
pDispInfo->item.pszText=Message;
}
My question is:
In example 1, can I assume that the buffer pItem->pszText will have enough
space for my text and that it will be freed when no longer necessary?
In example 2, am I supposed to free the memory in pItem->pszText? If so,
when is it safe for me to do it?
Or what is the correct way to do it without memory leaks?
Thanks