Serialization of GUID variable in MFC
I'm trying to serialize a GUID object in MFC. When I try to archive, I get the following error
Quote:
binary '<<' : no operator defined which takes a right-hand operand of type 'struct _GUID' (or there is no acceptable conversion)
My code snippet is this
Code:
void MyClass :: Serialize(CArchive &ar)
{
CObject::Serialize( ar );
if( ar.IsStoring())
{
ar << m_GUIDVariable;
}
else
{
ar >> m_GUIDVariable;
}
}
How shall I proceed?
Re: Serialization of GUID variable in MFC
struct _GUID is a structure. 'ar <<' doesn't know what to do with structures. So you will have to do member by member.
Code:
ar << m_GUIDVariable.Data1;
ar << m_GUIDVariable.Data2;
... etc
Re: Serialization of GUID variable in MFC
Quote:
Originally Posted by
Skizmo
struct _GUID is a structure. 'ar <<' doesn't know what to do with structures. So you will have to do member by member.
Code:
ar << m_GUIDVariable.Data1;
ar << m_GUIDVariable.Data2;
... etc
OK. Thanks.
Re: Serialization of GUID variable in MFC
GUID is a structure of PODS so you should be able to serialize with CArchive::Write() and Read():
Code:
void MyClass :: Serialize(CArchive &ar)
{
CObject::Serialize( ar );
if( ar.IsStoring())
{
ar.Write(&m_GUIDVariable,sizeof(GUID));
}
else
{
ar.Read(&m_GUIDVariable,sizeof(GUID));
}
}