Microsoft KB Archive/173252

= FIX: CArchive::GetObjectSchema Returns Incorrect Schema =

Article ID: 173252

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q173252

<div class="symptoms_section">

SYMPTOMS
CArchive::GetObjectSchema returns the schema of the object loading the serialized information rather than the schema of the object being loaded. This occurs only when an object with a schema greater than 0 loads an object with a schema equal to 0 and the object being loaded is not the first of this type.

<div class="cause_section">

CAUSE
When the first object of a type that has a schema of 0 is loaded, the value of the CArchive member, m_nObjectSchema, is set to a value of 0. When further objects of the same type are loaded, m_nObjectSchema is set to the schema of the object loading the serialized information.

This behavior is due to the way CArchive::ReadClass determines the schema of a type that has already been stored. This is done in the following code located toward the end of CArchive::ReadClass: // determine schema stored against objects of this type void* pTemp; if (m_pSchemaMap != NULL &&     (pTemp = m_pSchemaMap->GetValueAt(pClassRef)) != NULL) nSchema = (UINT)pTemp; else nSchema = pClassRef->m_wSchema & ~VERSIONABLE_SCHEMA; When the schema of a type that has already been loaded is 0 the value returned from GetValueAt is 0 and the else part of the if statement is executed. This sets the value of the schema for the object being loaded as the schema of the existing object.

<div class="resolution_section">

RESOLUTION
There are two ways to work around this issue:


 * Do not use a schema of 0 to serialize object information. This is the simplest solution but may not be practical if objects of schema 0 must be maintained. -or-


 * Set a flag when you load objects of schema 0. This flag should be considered when testing for schema number when using Archive::GetObjectSchema. The time to set this flag is when the first object with schema 0 is being loaded.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 3.

For more information, please see the following article in the Microsoft Knowledge Base:

170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why

Keywords: kbbug kbfix kbvs97sp3fix KB173252

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.