Solved

CObList Serialization in MFC Extension DLL

Posted on 1997-09-09
2
594 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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 174
Shell script to login to remote m/c and execute commands 10 79
fizzArray  challenge 1 109
matchUp  challenge 6 78
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

697 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