Serialization with version

I added a data member to a class that had a Serialize() function. The Serialize() function didn't support versioning. Now I want to serialize the new data member but to be compatible with previous serializaions.
My class has DECLARE_SERIAL(...) and IMPLEMENT_SERIAL(...,...,VERSIONABLE_SCHEMA|1) but when I use the function CArchive::GetObjectSchema() I always get -1.
I can't distinguish between old versions and new ones.
The class I serialize is an item in a CMap object that I serialize in another class.
How can I distinguish the different versions?
Thanks, Tomer
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here are couple of cpomments regrading using GetObjectSchema
1. Only call it one object is being loaded.
2. Make sure that it is called before you start reading any data from the object.
3. Call it only once. If you will call ut second time, it will return -1.

Example of impelementing two version...
two versions 0 and 1.
version 0 has two variables var1, var2...
version 1 has three m_Var1, m_var2, m_Var3


void CMyObject::Serialize (CArchive &ar)
 CObject:;Serialize (ar);
 if (ar.IsStoring ()) {
  ar << m_Var1 << m_Var2 << m_Var3;
 else {
  UINT nSchema = ar.GetObjectSchema ();
  switch (nSchema) {
   case 0:
     ar >> m_Var1 >> m_Var2;
     m_Var3 = /* Some default value*/;
   case 1:
     ar >> m_Var1 >> m_Var2 >> m_Var3;
     AfxThrowArchiveException (CArchiveException::badSchema);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TomersAuthor Commented:
The answer I got was like what I already read in the VC++ documents. The problem
is it didn't work, maybe because it was items in a CMap.
Anyway I solved it by trying to read it once with 3 arguments and if I encounter an
exception, I close the archive and open it again trying to read 2 arguments.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.