zrbite
July 15th, 2002, 01:07 PM
I have a problem with memory leaks using lParam. I am using a Tree control, and when adding an item, I set the lParam to a variable using char*. However, if I free that char*, the lParam value is gone later on. Using strdup works, but causes memory leaks after closing the application.
cdir is a std::string which as an example, will have a value of
"c:\zrbite\programs"
char* temp = strdup(cdir.c_str());
TVITEM item;
TVINSERTSTRUCT itemstr;
item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
item.lParam = (LPARAM) (LPCTSTR) temp;
item.pszText = title;
item.iImage = 1;
item.iSelectedImage = 1;
itemstr.hParent = parent.hItem;
itemstr.item = item;
CtlDir.InsertItem(&itemstr);
free(temp);
The lParam doesn't work because temp is freed. However, having strdup(temp) to set lParam causes a memory leak also.
cdir is a std::string which as an example, will have a value of
"c:\zrbite\programs"
char* temp = strdup(cdir.c_str());
TVITEM item;
TVINSERTSTRUCT itemstr;
item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
item.lParam = (LPARAM) (LPCTSTR) temp;
item.pszText = title;
item.iImage = 1;
item.iSelectedImage = 1;
itemstr.hParent = parent.hItem;
itemstr.item = item;
CtlDir.InsertItem(&itemstr);
free(temp);
The lParam doesn't work because temp is freed. However, having strdup(temp) to set lParam causes a memory leak also.