Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Serialization Problem

Posted on 1999-01-13
2
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 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