Microsoft KB Archive/151030

= PRB: Data Corruption with LBS_SORT and CCheckListBox on Win32s =

Article ID: 151030

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 2.0 Professional Edition

 Microsoft Visual C++ 2.1

 Microsoft Visual C++ 2.2

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q151030

<div class="symptoms_section">

SYMPTOMS
A CCheckListBox with the LBS_SORT style incorrectly copies the item data. Different strings in the listbox point to the same item data object. In debug mode using Visual C++ 4.0 and 4.1, this behavior will ASSERT in DBGHEAP.C as _free_dbg is called on the same memory block multiple times.

This is only a problem in Win32s.

<div class="cause_section">

CAUSE
This is a problem in Win32s with owner-draw listboxes that have the LBS_HASSTRINGS and LBS_SORT listbox styles. CCheckListBox is an owner-draw listbox that uses LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE with LBS_HASSTRINGS. CCheckListBox uses the item data to maintain the check state information for each item.

<div class="resolution_section">

RESOLUTION
To work around this behavior, avoid the LBS_SORT style or use InsertString instead of AddString. InsertString does not cause a LBS_SORT list to be sorted.

If the listbox needs to be sorted, the strings should be sorted before being added to the listbox or the strings should be inserted in order.

<div class="status_section">

STATUS
This behavior is by design.

Additional query words: 2.00 2.10 2.20 4.00 4.10 CListBox list box

Keywords: kbctrl kblistbox kbprb KB151030

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.