0

I'm working with legacy code in VS2010 and moved many data structures from using short and float to using int and double, respectively, to fix many compiler warnings.

However, it seems like this broke the mfc serialization (CArchive), as I cannot read old serialized data anymore. I tried casting and using temporary variables, but the results are not encouraging. Some variables are read correctly, others look like overflowed values, so what I'm really looking for is a way to make sure the ">>" operator only reads a short or a float.

One option is reverting to the old structure of course, but if possible, I would like to stick with the "more modern" datatypes and fix the procedure reading the serialized data. Is this possible, and if so, how can it be done?

Lars
  • 77
  • 2
  • 9

1 Answers1

0

Try with using version schema:


IMPLEMENT_SERIAL(CMyObject, CObject, VERSIONABLE_SCHEMA| new_version_schema)

void CMyObject::Serialize(CArchive& ar) 
{
   if (ar.IsLoading())
   {
      int nVersion = ar.GetObjectSchema();

      switch(nVersion)
      {
      case old_version_schema:
         // read old types short and float convert them to int and double
         break;
      case new_version_schema:
         // read new types int and double
         break;
      default:
         // report unknown version of 
         // this object
         break;
      }
   }
   else
   {
      // new save with int and double
   }

Sasha
  • 846
  • 5
  • 9
  • It was something like that I had in mind. My problem is in the "read old types short and float convert them to int and double" part. Some values are read correctly, others are read into wrong variable, and yet others seem like overflowed values. – Lars Aug 30 '12 at 08:45
  • I think, since you have some variables read correctly and some not, I expect that you still have some classes which are not reading the data properly in old version format. Just one mistake in one class will break the reading for flowing classes which are read. – Sasha Aug 30 '12 at 09:08
  • I may have fixed the problem now. Casting a few selected values to (float&) seems to fix the issue. Any idea why this happens with just a few values and the rest are ok? These are within a class like you wrote, does that change matters? – Lars Aug 30 '12 at 13:03