Serializaion and CRunTimeClass problems in VC7.1

M

Mack

Howdy,

I am trying to convert my project to Visual C++ 7.1 and have the
following severe problem (my previous compiler was VC 6.0 which seems
to work just fine).
My Application is trying to serialize and deserialize a (rather
simple) class of mine to a binary file, but when trying to deserialize
it I get an exception saying that the file "contained an unexpected
object"

Apparantly when trying to create the new class from the file,
CArchive::ReadClass calls CRunTimeClass::Load() which in turn calls
CRuntimeClass* pClass = FromName(szClassName);
But FromName cannot find my class for some reason and returns NULL

(needless to say, The class is perfectly serializable in VC6)

Now, I have tried some ideas posted by some and I rewrote the
Implement_serial macro as suggested like this:

#undef IMPLEMENT_SERIAL

#define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
CObject* PASCAL class_name::CreateObject() \
{ return new class_name; } \
extern AFX_COMDAT AFX_CLASSINIT _init_##class_name; \
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
class_name::CreateObject, &_init_##class_name) \
AFX_COMDAT AFX_CLASSINIT
_init_##class_name(RUNTIME_CLASS(class_name)); \
CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
{ pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name)); \
return ar; }


but none of that worked.

(BTW my class is defined and exported in a different DLL)

Any help and ideas will be greatly appreciated.

Mack
 
D

Dave Harris

Mack said:
Apparantly when trying to create the new class from the file,
CArchive::ReadClass calls CRunTimeClass::Load() which in turn calls
CRuntimeClass* pClass = FromName(szClassName);
But FromName cannot find my class for some reason and returns NULL

Are you sure your class is linked into the DLL? I have known the linker to
remove stuff it thought wasn't needed, if
it was only needed by serialisation.

Are you sure the DLL is loaded? When it loads, it should register all its
classes. You might want to try debugging that process. Check that your class
is registered under the right name. Maybe print out the list of known
classes that the serialisation is searching.

Are you sure you don't have multiple copies of MFC loaded? Eg due to linking
the DLL with v6 and the EXE with v7. That can lead to classes getting
registered into the wrong place.

-- Dave Harris
 
Top