FIX: COleDateTime::Format Throws a COleException(scode=E_FAIL) (167169)
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.0a
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Editions 4.2b
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
This article was previously published under Q167169 SYMPTOMS
When you attempt to use COleDateTime(DWORD, LCID) to extract the Date or
Time value, an exception with scode = E_FAIL occurs.
CAUSE
A bug in the Operating System causes this problem.
RESOLUTION
This problem only occurs if the LCID argument in the Format function is set
to anything other than English (United States), or if the Regional Settings
in WinNT/Win95 Control Panel is set to something other than
English (United States).
You can workaround the problem by using the "%x" or "%X" formatting codes.
The "%x" gives the Date representation and "%X" gives the Time
representation. For example:
CString str = dt.Format("%x");
CString str = dt.Format("%X");
However, they only give the Date format in the US style.
To get the date in the user-default locale, use the code in the MORE
INFORMATION section of this article. Wrap the call to Format as shown
below:
...
#include "locales.h"
...
CString str;
{
CSetLocale l(LC_TIME);
str = dt.Format("%x");
str = dt.Format("%X");
}
...
If you want the date in a particular LCID, then use the following to
construct the CSetLocale object:
LCID LCIDVALUE = <set it to the required value>;
CSetLocale l(LC_TIME, LCIDVALUE);
This code makes sure that the runtime locale is set to the correct locale
before the call to Format is made. The locale is reset to the previous
locale once the CSetLocale object is destroyed.
STATUS
This problem was corrected in Visual C++ version 6.0 for Windows.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbbug kbcode kbfix kbNoUpdate kbVC600fix KB167169 |
---|
|