Microsoft KB Archive/99199

{|
 * width="100%"|

PRB: CWnd::GetWindowText(CString &) Asserts w/ Drop-Down Combo

 * }

Q99199

-

The information in this article applies to:


 * The Microsoft Foundation Classes (MFC), included with:
 * Microsoft Visual C++, versions 1.0, 1.5, 1.51, 1.52

-

SYMPTOMS
An attempt to call CWnd::GetWindowText(CString & rString) fails and an assertion occurs in STRCORE.CPP on line 336 if the CWnd object specifies a drop list combobox (a combobox with the CBS_DROPDOWNLIST window style).

The assertion in Visual C++ occurs on line 276 of STRCORE1.CPP.

CAUSE
The CWnd::GetWindowText(CString& ) function calls GetWindowTextLength. If this function is called for a drop list ComboBox, Windows incorrectly returns -1 (CB_ERR). This is a bug in Windows. Because a CString can't have a length of -1, the application framework of MFC correctly displays an assertion.

RESOLUTION
To work around this problem, use the CWnd::GetWindowText(LPSTR, INT) function; it does not call GetWindowTextLength. If you want to use a CString in your application, use code like the following:

  CString s;   char* p = s.GetBuffer(10); // Allocate space for 10 characters. pComboBox->GetWindowText(p, 10); s.ReleaseBuffer; Additional query words: 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52 noupdate no32bit

Keywords : kb16bitonly kbMFC KbUIDesign kbVC kbprb

Issue type : kbprb

Technology : kbAudDeveloper kbMFC