Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Serialization Problem

Posted on 1999-01-13
2
Medium Priority
?
207 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

971 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