PRB: CWnd::GetWindowText(CString &) Asserts w/ Drop-Down ComboLast reviewed: July 17, 1997Article ID: Q99199 |
1.00 1.50 1.51 1.52
WINDOWS
kbprg kbprb
The information in this article applies to:
SYMPTOMSAn 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.
CAUSEThe 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.
RESOLUTIONTo 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 reference words: 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |