Stores the specified CObject to the archive.
This function is normally called by the CArchive insertion (<<) operator overloaded for CObject. WriteObject, in turn, calls the Serialize function of the archived class.
You must use the IMPLEMENT_SERIAL macro to enable archiving. WriteObject writes the ASCII class name to the archive. This class name is validated later during the load process. A special encoding scheme prevents unnecessary duplication of the class name for multiple objects of the class. This scheme also prevents redundant storage of objects that are targets of more than one pointer.
The exact object encoding method (including the presence of the ASCII class name) is an implementation detail and could change in future versions of the library.
Finish creating, deleting, and updating all your objects before you begin to archive them. Your archive will be corrupted if you mix archiving with object modification.
For a definition of the class CAge, see the example for CObList::CObList.
CFile myFile(_T("My__test__file.dat"), CFile::modeCreate | CFile::modeReadWrite); CAge age(21), *pAge; // Create a storing archive. CArchive arStore(&myFile, CArchive::store); // Write the object to the archive arStore.WriteObject(&age); // Close the storing archive arStore.Close(); // Create a loading archive. myFile.SeekToBegin(); CArchive arLoad(&myFile, CArchive::load); // Verify the object is in the archive. pAge = (CAge*) arLoad.ReadObject(RUNTIME_CLASS(CAge)); ASSERT(age == *pAge);