BUG: DDX Problem with Combo Box in Win32s (139593)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 2.2
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
This article was previously published under Q139593 SYMPTOMS
The DDX function DDX_CBString does not work correctly under Win32s for
combo boxes that use the drop list style. If you try to use DDX to retrieve
the string associated with the static control of a drop list style combo
box under Win32s, an empty string is returned.
CAUSE
This problem is the result of an improperly sign extended return value from
the Windows SDK GetWindowTextLength function. The MFC function DDX_CBString
uses GetWindowTextLength to try to determine how many characters to copy
from the edit control of a combo box with a drop down style or the static
control of a combo box with a drop list style. The GetWindowTextLength
function fails to retrieve a valid text length for a combo box with a drop
list style under Win32s. When GetWindowTextLength is called for a combo box
with a drop list style under Win32s, a value of 0xFFFF is returned. Because
this return value isn't properly sign extended to 0xFFFFFFFF, the
DDX_CBString function doesn't work correctly.
RESOLUTION
It is possible to work around this problem by providing your own
implementation of the DDX_CBString function for the class that has the
DDX_CBString call in its DoDataExchange function. If you provide your own
DDX_CBString member function, it will override the standard MFC
DDX_CBString function. To provide your own version of DDX_CBString follow
these steps: - Add the following function to your class header file:
void DDX_CBString(CDataExchange *pDX, int
nIDC, CString& value);
- Add the implementation for this function to your classes implementation
file. See the "Sample Code" section in this article for an example of a
revised implementation of DDX_CBString for a class called CMyTryDlg.
- In your implementation file, use #include to include the Afxpriv.h file.
- Inside the implementation for this function, copy all the MFC code for
the standard MFC DDX_CBString function. The standard MFC DDX_CBString
function can be found in the MFC source file Dlgdata.cpp.
- Change this line:
if (nLen != -1)
to this line:
if (nLen!= -1 && nLen!=0xFFFF)
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. We are researching this problem and will
post new information here in the Microsoft Knowledge Base as it becomes
available.
Visual C++ versions 4.2 and later do not support building Win32s
applications.
Modification Type: | Major | Last Reviewed: | 10/17/2003 |
---|
Keywords: | kbbug kbDlg kbprogramming kbui KB139593 |
---|
|