Re: ComboBox DeleteItem() not being called for all items?
- From: Giovanni Dicanio <giovanniDOTdicanio@xxxxxxxxxxxxxxxxx>
- Date: Thu, 11 Dec 2008 11:47:22 +0100
To add to what I wrote in previous message (not related to your main problem, but might be worth writing):
AndersG wrote:
> I finally got the time to investigate further and this is what I have:
void CLpCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
// Delete CString pointed to by item.
TRACE("\nDeleting %d from control %d (%s)",
lpDeleteItemStruct->itemID,
lpDeleteItemStruct->CtlID,
*((CString*)lpDeleteItemStruct->itemData));
delete (CString*)lpDeleteItemStruct->itemData;
When you have a %s and you want to pass a CString, it now works, but is considered not very safe.
It works because of some "magic" in the internal design of CString, but if you have a %s and variable argument list, is better to explicitly static_cast to LPCTSTR, or use CString::GetString() method, e.g.
CString str;
int x;
int y;
TRACE("Some data: %d, %s, %d", x, str.GetString(), y );
So, I would adjust your code a bit like this:
void CLpCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
// Get custom CString pointer from lpDeleteItemStruct
CString * pstr =
reinterpret_cast<CString *>( lpDeleteItemStruct->itemData );
// Trace deletion
TRACE("\nDeleting %d from control %d (%s)",
lpDeleteItemStruct->itemID,
lpDeleteItemStruct->CtlID,
pstr->GetString()));
// Free previously allocated CString
delete pstr;
}
Giovanni
.
- Follow-Ups:
- Re: ComboBox DeleteItem() not being called for all items?
- From: AndersG
- Re: ComboBox DeleteItem() not being called for all items?
- From: AndersG
- Re: ComboBox DeleteItem() not being called for all items?
- References:
- ComboBox DeleteItem() not being called for all items?
- From: AndersG
- ComboBox DeleteItem() not being called for all items?
- Prev by Date: Re: ComboBox DeleteItem() not being called for all items?
- Next by Date: IE window in BHO and in the same process
- Previous by thread: Re: ComboBox DeleteItem() not being called for all items?
- Next by thread: Re: ComboBox DeleteItem() not being called for all items?
- Index(es):
Relevant Pages
|