Solved

Serialization Problem

Posted on 1999-01-13
2
200 Views
Last Modified: 2013-11-20
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
   }

}
0
Comment
Question by:winkle
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1327654
What are the types of the data members you are trying to serialize? Are any of them strings?

If so, you should use ar.ReadString() and ar.WriteString() to serialize them instead of using << and >>.
0
 

Author Comment

by:winkle
ID: 1327655
Ahhhh, yes 90% of the data are type CString. Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
sumDigits challenge 9 148
either24  challenge 19 97
Bartender label printing - switch on and off graphics 3 38
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question