FIX: Access Violation in RFX_Date If CTime Not Initialized (155721)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
This article was previously published under Q155721 SYMPTOMS
An application may fail with an access violation while executing the
RFX_Date() function. A message similar to the following appears:
Unhandled exception in My.exe (MFC42D.DLL):
0xC0000005: Access Violation.
CAUSE
The RFX_Date() function in MFC 4.2 now requires initialization of CTime
objects. Versions of MFC earlier than 4.2 do not have this requirement.
AppWizard and ClassWizard do not initialize the CTime member variables for
you.
Because CTime member variables are not initialized in the CRecordset
constructor, an access violation can occur when RFX_Date() tries to use the
uninitialized data.
RESOLUTION
Initialize the CTime member variables in the constructor of your CRecordset-
derived class. The following is one way to initialize the CTime member
variable:
m_myTime = CTime::GetCurrentTime();
STATUS
This problem was corrected in the MFC AppWizard included with Microsoft
Visual C++, version 5.0. CTime member variables are now assigned a value of
zero by the AppWizard. If a CRecordset class is manually added to your
project that contains an empty recordset you still need to initialize the
CTime member variable as explained in the RESOLUTION section.
Modification Type: | Major | Last Reviewed: | 11/18/2003 |
---|
Keywords: | kbBug kbcode kberrmsg kbfix kbVC500fix KB155721 |
---|
|