質問

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?

役に立ちましたか?

解決

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
   }

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top