Link to home
Start Free TrialLog in
Avatar of winkle
winkle

asked on

Serialization Problem

I have a CObject based class that I'm serializing. Some of my files do not get read back in properly. They generate a bad format error. What appears to be happening is that certain data sets write out 0x0d characters. (I have two test files. One is always fine the other always fails. But the data is fine in both cases. I see no differences.) This is throwing thing off when I load the data back in. I've stepped through the storing process and the data is fine.

Has anyone run into anything similar? I'm at a loss as to what could be causing this. And I'm wondering if there are other things I should be checking that I'm unaware of.

Here's my Serialization function:

void CSenseInformation::Serialize( CArchive& ar)
{
  BOOL tag = FALSE;
  ar.SerializeClass(RUNTIME_CLASS(CSenseInformation));
  CObject::Serialize(ar);

  if (ar.IsStoring()) {

    ar << m_currSense << m_fileSense << m_fileDef;
    ar << m_currSenseNum << m_deriveFlag;
    ar << m_currSenseBase;

  } else {    // loading, not storing

    UINT nSchema = ar.GetObjectSchema();

    switch (nSchema) {
    case 0:
    case 1:
      ar >> m_currSense >> m_fileSense >> m_fileDef;
      ar >> m_currSenseNum >> m_deriveFlag;
      ar >> m_currSenseBase;
      break;
    default:
           AfxThrowArchiveException(CArchiveException::badSchema);
      break;
    } // switch
   }

}
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of winkle
winkle

ASKER

Ahhhh, yes 90% of the data are type CString. Thanks!