Click here to Skip to main content
Licence CPOL
First Posted 14 Dec 2002
Views 30,887
Bookmarked 10 times

Macro to make a class serializable in VC 6.0 MFC projects

By | 14 Dec 2002 | Article
A simple macro that adds all the code necessary to make a class serializable in a MFC 6.0 application.

Introduction

According to MSDN, five main steps are required to make a class serializable.

  • Deriving your class from CObject (or from some class derived from CObject).
  • Overriding the Serialize member function.
  • Using the DECLARE_SERIAL macro in the class declaration.
  • Defining a constructor that takes no arguments.
  • Using the IMPLEMENT_SERIAL macro in the implementation file for your class.

This macro is a simple VS macro that would do all this for you.

What's added?

In the interface for the class the following lines are added:

  DECLARE_SERIAL(class name)
  public:
  void     Serialize(CArchive& archive);

and also add:

 : public CObject

in front of class name.

In the implementation of the class, the following line is added:

  IMPLEMENT_SERIAL(class name, CObject, 1)

and an implementation is also added for Serialize(CArchive& archive) function.

void SomeClass::Serialize(CArchive& archive)
{
   if(archive.IsStoring()){

   } // if(archive.IsStoring())
   else{

   } // else --> if(archive.IsStoring())
}

How to install

Simply save the MakeSerializable.dsm file in your <Visual Studio>/Common/MSDev98/Macros/ folder. Then, in Dev Studio, select the Tools menu, Macro dialog. On the Macro dialog, click the Options button to show an extra four buttons. Click the Loaded Files button to bring up another dialog. Scroll down the list of macro files until you find MakeSerializable. Select the check box for MakeSerializable.

That's it! I hope someone finds this useful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ali Khanlarkhani

Software Developer (Senior)
Barayand Pioneer Technologies Co. Ltd.
Iran (Islamic Republic Of) Iran (Islamic Republic Of)

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGood article. PinmemberJeanWaljean18:48 6 Sep '10  
GeneralMore on serialization PinmemberRavi Bhavnani7:31 15 Dec '02  
GeneralRe: More on serialization PinmemberAli Khanlarkhani21:48 15 Dec '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 15 Dec 2002
Article Copyright 2002 by Ali Khanlarkhani
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid