Search code examples
carchive

Using CArchive::GetObjectSchema returns wrong value


I have a problem here. In my main application header file I have these definitions:

#define SOUNDROTA_VERSION_171801    171801 // 17.1.8 Beta 1
#define SOUNDROTA_VERSION_CURRENT   171801 // 17.1.8 Beta 1

In my application I have a CObject derived class which has this at the top:

IMPLEMENT_SERIAL(CChristianLifeMinistryEntry, CObject, VERSIONABLE_SCHEMA | SOUNDROTA_VERSION_CURRENT)

Things have always worked fine when using the schema value up until now. I admit that previously the values I was using were smaller, like 1707 for 17.0.7 but I was trying to factor in for beta versions too and thus larger numbers.

void CChristianLifeMinistryEntry::Serialize(CArchive& ar)
{
    CObject::Serialize(ar);

    if (ar.IsStoring())
    {   // saving code
    else
    {   // loading code
    UINT uSchema = ar.GetObjectSchema();
        if (uSchema >= SOUNDROTA_VERSION_171801)
        {
            AfxMessageBox(_T("Booh"));
        }
        else
        {
        }
    }
}

My problem is, when I save a data file and then re-open it, the uSchema has a value of 40729.

Why? GetObjectSchema returns a UNIT so why am I not getting the schema I specified?

Update

If I use a value of 1718 then it returns that value.


Solution

  • According to the legacy sources of MFC and CRuntimeClass class, (which can be found in subfolders of Visual Studio), the version is serialised as a WORD value and 0xFFFF is reserved. Therefore, it appears that version cannot be greater than 0xFFFE (65534).