Serialization of GUID variable in MFC
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Serialization of GUID variable in MFC

  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    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

    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?
    Rate the posts which you find useful

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    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

  3. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    408

    Re: Serialization of GUID variable in MFC

    Quote Originally Posted by Skizmo View Post
    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.
    Rate the posts which you find useful

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    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));
          }
        }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center