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()){
} else{
} }
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.