Subclassing a listbox and the speed of the postal service
I'm currently subclassing a listbox, with a view to turning it into a property viewer as featured in the Visual Basic IDE. The thing is, I've added a new message to the WindowProc which adds a property to the window and at this early stage that effectively means some basic formatting and using LB_ADDSTRING twice. It looks something like this:-
The property's name is immediately added to the listbox (Because this window is a subclassed listbox, I'm sending it to itself). After the data is formatted into the szTemp string it's also added. However, while the first LB_ADDSTRING message seems to work properly (The name is visible in the listbox), the second one, while a valid string is passed to it, doesn't (Lovely big row of "í" :o).
PVITEM *pvi = (PVITEM *)lParam;
ret = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)pvi->pszText);
// I do some formatting stuff here (tons of switch(...) :p)
ret = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)szTemp);
What is strange is that ret, which is supposed to give the index of the new string, doesn't appear to change between the two commands. Replacing "szTemp" with a string constant (such as "0") works, so I think the memory the string's occupying is being freed before the call is finished, some sort of reentrant problem. Help? :D