COleClientItem::Serialize problem
Bob_Trabucco@HarveyMail1.CCMAIL.CompuServe.COM
Thursday, April 03, 1997
Environment: VC++ 1.52, Win 3.x, 95
I have a COleDocument derived class that contains objects of a
COleClientItem derived class. All is well when my project is compiled
in debug mode, but when I compile in release mode it fails on the
COleClientItem::Serialize() call in my COleClientItem derived class's
Serialize() method. The system displays a message box with the error
"Failed to open document". Since this only happens in release mode I
am having a very hard time tracing this one down. I have tried
turning off the optimizations with no effect. All other
compiler/linker options look the same in both the debug and release
settings with the exception of the library I am linking. Any insight
is appreciated. Source code follows...
Thanks in advance
Bob Trabucco
Harvey Software, Inc.
Sample Code:
//////////////////////////////////////////////////////////////////////
///////
// CReportsDoc
IMPLEMENT_DYNCREATE(CReportsDoc, COleDocument)
BEGIN_MESSAGE_MAP(CReportsDoc, COleDocument)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
///////
// CReportsDoc construction/destruction
CReportsDoc::CReportsDoc()
{
// For most containers, using compound files is a good idea.
EnableCompoundFile();
docEditable = TRUE;
}
//////////////////////////////////////////////////////////////////////
///////
// CReportsDoc serialization
void CReportsDoc::Serialize(CArchive& ar)
{
WORD w = 0;
if (!ar.IsStoring())
{
ar >> w >> docTitle >> docEditable;
if (w != 0xAA55)
AfxThrowArchiveException(CArchiveException::generic);
}
COleDocument::Serialize(ar);
}
//////////////////////////////////////////////////////////////////////
///////
// CCntrItem implementation
IMPLEMENT_SERIAL(CCntrItem, COleClientItem, 0)
CCntrItem::CCntrItem(CReportsDoc* pContainer)
: COleClientItem(pContainer)
{
}
void CCntrItem::Serialize(CArchive& ar)
{
WORD w = 0;
ASSERT_VALID(this);
// FAILS DURING THIS CALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
COleClientItem::Serialize(ar);
// now store/retrieve data specific to CCntrItem
if (!ar.IsStoring())
{
ar >> w >> m_extent >> m_rect >> m_title >> m_command >>
m_graphic;
if (w != 0x55AA)
{
AfxThrowArchiveException(CArchiveException::generic);
}
}
}
It fails when I do the following:
CReportsDoc *pDoc = new CReportsDoc();
pDoc->OnOpenDocument(filename);
Hugh Robinson -- hugh@ssihou.ssii.com
Thursday, April 03, 1997
[Mini-digest: 3 responses]
General hint
=========
One good place to look for release mode only bugs is in ASSERT statements
such as
CMyClass* ptr;
ASSERT( NULL ! = (ptr = foo()) ); // ASSERT that ptr is not NULL
ptr->foo2()
since in release mode the function foo() will not be called. Even if you
are aware of this, you can still do it. I know, I have...
One solution here is to use VERIFY in place of ASSERT.
Your Specific code
==============
However, with your code is as you have supplied it, then you would appear
to have a bug in that whatever you read from your archive you should have
written to it (suggested fix below):
void CReportsDoc::Serialize(CArchive& ar)
{
WORD w = 0;
if (!ar.IsStoring())
{
ar >> w >> docTitle >> docEditable;
if (w != 0xAA55)
AfxThrowArchiveException(CArchiveException::generic);
}
//***new code start
else {
ar << w << docTitle << docEditable;
}
//***new code end
COleDocument::Serialize(ar);
}
----------
From: owner-mfc-l
Sent: Thursday, April 03, 1997 3:58 PM
To: mfc-l
Subject: COleClientItem::Serialize problem
Environment: VC++ 1.52, Win 3.x, 95
I have a COleDocument derived class that contains objects of a
COleClientItem derived class. All is well when my project is
compiled
in debug mode, but when I compile in release mode it fails on the
COleClientItem::Serialize() call in my COleClientItem derived
class's
Serialize() method. The system displays a message box with the
error
"Failed to open document". Since this only happens in release mode
I
am having a very hard time tracing this one down. I have tried
turning off the optimizations with no effect. All other
compiler/linker options look the same in both the debug and release
settings with the exception of the library I am linking. Any
insight
is appreciated. Source code follows...
Thanks in advance
Bob Trabucco
Harvey Software, Inc.
Sample Code:
/////////////////////////////////////////////////////////////////////
/
///////
// CReportsDoc
IMPLEMENT_DYNCREATE(CReportsDoc, COleDocument)
BEGIN_MESSAGE_MAP(CReportsDoc, COleDocument)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////
/
///////
// CReportsDoc construction/destruction
CReportsDoc::CReportsDoc()
{
// For most containers, using compound files is a good idea.
EnableCompoundFile();
docEditable = TRUE;
}
/////////////////////////////////////////////////////////////////////
/
///////
// CReportsDoc serialization
void CReportsDoc::Serialize(CArchive& ar)
{
WORD w = 0;
if (!ar.IsStoring())
{
ar >> w >> docTitle >> docEditable;
if (w != 0xAA55)
AfxThrowArchiveException(CArchiveException::generic);
}
COleDocument::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////
/
///////
// CCntrItem implementation
IMPLEMENT_SERIAL(CCntrItem, COleClientItem, 0)
CCntrItem::CCntrItem(CReportsDoc* pContainer)
: COleClientItem(pContainer)
{
}
void CCntrItem::Serialize(CArchive& ar)
{
WORD w = 0;
ASSERT_VALID(this);
// FAILS DURING THIS CALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
COleClientItem::Serialize(ar);
// now store/retrieve data specific to CCntrItem
if (!ar.IsStoring())
{
ar >> w >> m_extent >> m_rect >> m_title >> m_command >>
m_graphic;
if (w != 0x55AA)
{
AfxThrowArchiveException(CArchiveException::generic);
}
}
}
It fails when I do the following:
CReportsDoc *pDoc = new CReportsDoc();
pDoc->OnOpenDocument(filename);
-----From: =?iso-8859-1?Q?Klaus_G=FCtter?=
Bob,
are the Serialize functions you posted here complete?
If yes: the code for the IsStoring and the IsLoading cases must be
completely symmetric.
So if you code
> ar >> w >> docTitle >> docEditable;
in the loading case, you must code
> ar << w << docTitle << docEditable;
when you store.
- Klaus
>----------
>Von:
> Bob_Trabucco@HarveyMail1.CCMAIL.CompuServe.COM[SMTP:Bob_Trabucco@HarveyMail1
>.CCMAIL.CompuServe.COM]
>Gesendet: Donnerstag, 3. April 1997 22:58
>An: mfc-l@netcom.com
>Betreff: COleClientItem::Serialize problem
>
> Environment: VC++ 1.52, Win 3.x, 95
>
> I have a COleDocument derived class that contains objects of a
> COleClientItem derived class. All is well when my project is compiled
> in debug mode, but when I compile in release mode it fails on the
> COleClientItem::Serialize() call in my COleClientItem derived class's
> Serialize() method. The system displays a message box with the error
> "Failed to open document". Since this only happens in release mode I
> am having a very hard time tracing this one down. I have tried
> turning off the optimizations with no effect. All other
> compiler/linker options look the same in both the debug and release
> settings with the exception of the library I am linking. Any insight
> is appreciated. Source code follows...
>
> Thanks in advance
>
> Bob Trabucco
> Harvey Software, Inc.
>
>
>
> Sample Code:
>
>
> //////////////////////////////////////////////////////////////////////
> ///////
> // CReportsDoc
>
> IMPLEMENT_DYNCREATE(CReportsDoc, COleDocument)
>
> BEGIN_MESSAGE_MAP(CReportsDoc, COleDocument)
> END_MESSAGE_MAP()
>
> //////////////////////////////////////////////////////////////////////
> ///////
> // CReportsDoc construction/destruction
>
> CReportsDoc::CReportsDoc()
> {
> // For most containers, using compound files is a good idea.
> EnableCompoundFile();
>
> docEditable = TRUE;
> }
>
> //////////////////////////////////////////////////////////////////////
> ///////
> // CReportsDoc serialization
>
> void CReportsDoc::Serialize(CArchive& ar)
> {
> WORD w = 0;
>
> if (!ar.IsStoring())
> {
> ar >> w >> docTitle >> docEditable;
>
> if (w != 0xAA55)
> AfxThrowArchiveException(CArchiveException::generic);
> }
>
> COleDocument::Serialize(ar);
> }
>
>
>
>
> //////////////////////////////////////////////////////////////////////
> ///////
> // CCntrItem implementation
>
> IMPLEMENT_SERIAL(CCntrItem, COleClientItem, 0)
>
> CCntrItem::CCntrItem(CReportsDoc* pContainer)
> : COleClientItem(pContainer)
> {
> }
>
> void CCntrItem::Serialize(CArchive& ar)
> {
> WORD w = 0;
> ASSERT_VALID(this);
>
>
> // FAILS DURING THIS CALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> COleClientItem::Serialize(ar);
>
> // now store/retrieve data specific to CCntrItem
> if (!ar.IsStoring())
> {
> ar >> w >> m_extent >> m_rect >> m_title >> m_command >>
> m_graphic;
>
> if (w != 0x55AA)
> {
> AfxThrowArchiveException(CArchiveException::generic);
> }
> }
> }
>
>
>
> It fails when I do the following:
>
>
> CReportsDoc *pDoc = new CReportsDoc();
>
> pDoc->OnOpenDocument(filename);
>
>
>
>
-----From: Bob_Trabucco@HarveyMail1.CCMAIL.CompuServe.COM
They are complete. These are for reading only, I do not want to
update the files, there will be another program for that, I posted
this one since it is the most straightforward. The saves and the reads
are symetrical. Both programs seem to fail the same way. The
COleClientItem::Serialize(ar) generates the error, never even getting
to the:
ar >> w >> m_extent >> m_rect >> m_title >> m_command >> m_graphic
The funny thing is that it does work perfectly in Debug mode. I even
went so far as to re-install Visual C++ in the hope that I had a bad
library.
Are there any differences between the Debug and Release libraries that
I should know about that can cause these type of problems???
Thanks,
Bob
______________________________ Reply Separator _________________________________
Subject: AW: COleClientItem::Serialize problem
Author: INTERNET:KG@it-gmbh.de at CSERVE
Date: 4/4/97 4:28 AM
Sender: KG@it-gmbh.de
Received: from svr-02.it-gmbh.de ([194.195.243.178]) by
arl-img-3.compuserve.com (8.6.10/5.950515)
id DAA11495; Fri, 4 Apr 1997 03:11:24 -0500
Received: by svr-02.it-gmbh.de with SMTP (Microsoft Exchange Server Internet
Mail Connector Version 4.0.993.5)
id <01BC40E0.8C35F690@svr-02.it-gmbh.de>; Fri, 4 Apr 1997 10:11:22 +0200
Message-ID:
From: =?iso-8859-1?Q?Klaus_G=FCtter?=
To: "'mfc-l@netcom.com'" ,
"'Bob_Trabucco@HarveyMail1.CCMAIL.CompuServe.COM'"
Subject: AW: COleClientItem::Serialize problem
Date: Fri, 4 Apr 1997 10:11:07 +0200
X-Mailer: Microsoft Exchange Server Internet Mail Connector Version 4.0.993.5
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Become an MFC-L member
| Вернуться в корень Архива
|