?
Solved

GetObjectSchema returns 0xffffffff

Posted on 2005-04-20
12
Medium Priority
?
554 Views
Last Modified: 2013-11-20
I have a document CMyDoc from CDocument

I've added the following line to the top of the .cpp file:

IMPLEMENT_SERIAL(MyDoc, CDocument, VERSIONABLE_SCHEMA|4)

And the following to the .h file:

DECLARE_SERIAL(CMyDoc)

In the CDocument serialize below, I always get 0xffffffff from GetObjectSchema. Why?

void CMyDoc::Serialize(CArchive& ar)
{
      //This function passes the archive on to the Network group
      //which in turn passes the archive to other lists & objects.
      
      if (ar.IsStoring())
      {
            ar << m_pNetwork;
      }
      else
      {
            UINT version = ar.GetObjectSchema();

            switch(version)
            {
            case 4:
                  ar >> m_pNetwork;
                  break;

            default:      
                                             //ALWAYS GOES HERE!!! WHY??      
                                   break;
            }
      }
}
0
Comment
Question by:JoyBurke
  • 7
  • 5
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13826437
>>I always get 0xffffffff from GetObjectSchema. Why?

A return value of (UINT)–1 indicates that the version number is unknown. You need to specify the schema in 'IMPLEMENT_SERIAL()', e.g.

IMPLEMENT_SERIAL( CMyDoc, CDocument, 4 )


0
 

Author Comment

by:JoyBurke
ID: 13826616
Jkr,

As I stated in my post, I have:

 IMPLEMENT_SERIAL(MyDoc, CDocument, VERSIONABLE_SCHEMA|4)

in MyDoc.cpp
0
 

Author Comment

by:JoyBurke
ID: 13827704
The "m_pNetwork" is a pointer derived from CObject. It saves the version just fine with the Implement_Serial stuff I put in.

It's only the Doc that's giving me trouble. Is there something special I need to do in an MDI app to make it work?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 13827729
>> The "m_pNetwork" is a pointer derived from CObject

Um, saving a pointer is kinda 'odd', since the next time you want to load the document, it's quite unlikely that you'll find an instance of the same class at the memory location you saved previously...
0
 

Author Comment

by:JoyBurke
ID: 13828266
Well, if you serialize a pointer to a CObject, it calls the "serialize" for that object. It does not store the pointer directly.
0
 

Author Comment

by:JoyBurke
ID: 13828286
But it really doesn't matter what I store

I've tried a simple int as a test.

It just doesn't get the version.
0
 

Author Comment

by:JoyBurke
ID: 13828310
Originally, the Document contained:

IMPLEMENT_DYNCREATE(CMyDoc, CDocument)

I changed this to:

IMPLEMENT_SERIAL(CMyDoc, CDocument, VERSIONABLE_SCHEMA|4)

Does the problem have something to do with that? The CObject that I can get to serialize fine did not have this line originally.
0
 
LVL 86

Expert Comment

by:jkr
ID: 13828431
Have you tried to use both 'IMPLEMENT_DYNCREATE()' and 'IMPLEMENT_SERIAL()'? The 1st one is needed for CObject support anyway.
0
 

Author Comment

by:JoyBurke
ID: 13828797
Can't do that... I get a compile error

Why do I need 'IMPLEMENT_DYNCREATE()' for CObjects?
0
 
LVL 86

Expert Comment

by:jkr
ID: 13828856
Well, as the docs put it:

Use the IMPLEMENT_DYNCREATE macro with the DECLARE_DYNCREATE macro to enable objects of CObject-derived classes to be created dynamically at run time. The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization

BTW, you also added 'DECLARE_DYNCREATE()'?
0
 

Author Comment

by:JoyBurke
ID: 13828868
OK -- I found the answer. "Serialize" is essentually called directly by the Save of the document. When called directly, the Schema will not be saved. The solution is to call

GetObjectSchema() only works if the object has been serialized with the CArchive &lt;&lt; operator. If the Serialize method is called directly the class schema is not saved.

You can force the Schema value to be stored by using SerializeClass() as follows.

void CMyDoc::Serialize(CArchive& ar)
{
ar.SerializeClass(RUNTIME_CLASS(CMyDoc));
if (ar.IsStoring())
{
// TODO: add storing code here

}
else
{
// TODO: add loading code here

int nVersion = ar.GetObjectSchema();
switch(nVersion)
{
case 1:
...
break;

...
...

}
}
}

Thanks for all your help. Just say "see fount above" and I'll accept your answer
0
 
LVL 86

Accepted Solution

by:
jkr earned 750 total points
ID: 13828894
You mean like "see above"? :o)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

839 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