Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CObList Serialization in MFC Extension DLL

Posted on 1997-09-09
2
Medium Priority
?
628 Views
Last Modified: 2013-11-20
 Environment: Visual C++5.0 WinNT 4.0

Hi,

I am trying to serialize a CObList in a similar manner to the Microsoft drawcli sample. The main differences are my code resides in an MFC extension DLL, while there code is in an EXE. Also their document is based on a COleDocument and mine is based on a standard CDocument.

I have included the implement serial and declare serial macros in the class and its CPP file. The object list is defined as:
    typedef CTypedPtrList<CObList, AZDRAWANNO*> CDrawObjList;

The problem I have is that dispite the fact that the serialize function in each of my objects is called the data is in some way corrupt because it will not reload; I get the error: "Unexpected File Format". In the CObList::Serialize code I have noticed that the number of objects is not initialized when attempting to load, although is correct when attempting to save.

I have also noticed that when I debug the Microsoft example the pNode object created in CObList::Serialize is defined as a CDrawRect *and* includes a node in the variables window labelled CDrawRect (allowing the data that is to be stored to be seen). When I debug my code the pNode object is defined as CDrawRect, but the CDrawRect node is missing.

Any suggestions?
0
Comment
Question by:sdj
[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
2 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1305969
Please send some more code to look at.

my email is mailto:Roger_Onslow@compsys.com.au
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1305970
YOu code contains this...

void AZDIBCONTAINER::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// Save the DIB image to disk.
GetDIBImage()->Save( ar.GetFile() );
}
else
{
// Load the DIB image from disk.
GetDIBImage()->Load( ar.GetFile() );
}
// load the annotations from disk. annotationList is the Object list, it
contains
// AZDRAWRECT objects derived from AZDRAWANNO derived from
// CObject. NOTE see previous article for typedef!
annotationList.Serialize( ar );
}


The problem is you are fiddling about with the file that CArchive is using - thie is NOT ON!!.  CArchive does not keep its file up to date all the time - it uses read buffers for effciency and for backtracking.

If both you and it try to write to (or read from) this file, then you are going to tread on each others feet (so to speal)


You should at least call CArchive::Flush() beofre (and after) trying to directly acess the file.  IN fact, the help for GetFile tells you to do this anyway.

Even better, avoid directly accessing the underlying file anyway - See if your DIB image class can be change to save and load from an archive (ie. implement a serialize function itself).  Or make it write to an in-memory buffer (maybe an in-memory file), then you can transfer that to/from the archive with the CArchive::Write/Read member functions.

In anycase, the problem is with this little bit of code, which stuffs up the file so the list doesn't serialize properly.  WHen you fix this, you should find the problem goes away.

Roger

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

636 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