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
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