Solved

Serialization Problem

Posted on 1999-01-13
2
197 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
Comment Utility
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
Comment Utility
Ahhhh, yes 90% of the data are type CString. Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Turn a spreadsheet into a vba executable. 2 66
if loop in java 3 113
modThree challenge 4 64
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now