FIX: Incorrect Return Values from COleDateTime Members (152781)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
This article was previously published under Q152781 SYMPTOMS
When you call the COleDateTime members (SetDate, SetTime, and SetDateTime),
the return value indicates failure even though the call is successful. This
may cause code that checks the return value to believe incorrectly that the
call failed.
CAUSE
This behavior is caused by a problem in the COleDateTime code. COleDateTime
defines the following enumeration:
enum DateTimeStatus
{
valid = 0,
invalid = 1, // Invalid date (out of range, etc.)
null = 2, // Literally has no value
};
The problem occurs because SetDate, SetTime, and SetDateTime all return
'valid' if successful. However 'valid' is defined to be 0 in the
DateTimeStatus enumeration, which translates to a Boolean FALSE. The code
should check for success and return TRUE or FALSE.
RESOLUTION
Call COleDateTime::GetStatus after each call to SetDate, SetTime, or
SetDateTime. Then compare the value returned by GetStatus() against 'valid'
to check for success. The "More Information" section of this article
provides an example.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug has been corrected in the Visual
C++ 4.2b technology update.
Modification Type: | Major | Last Reviewed: | 12/10/2003 |
---|
Keywords: | kbBug kbfix kbNoUpdate kbVC420fix KB152781 |
---|
|