Solved

CObList Serialization in MFC Extension DLL

Posted on 1997-09-09
2
601 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 50 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

Industry Leaders: 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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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