Chapter 29. Serialization

In this chapter we're going to talk about how to save information about your current document's data, and how to read that kind of information back in. This process used to be called file handling, but these days it's called serialization. To serialize a document means either to write it to a file, or to read information into it from a file. The word 'serialize' is used to express the notion that we are converting a complicated data object into a simple series, or sequence, of 0s and 1s.

The MFC framework makes it exceedingly easy to open and save files. One good thing is that the work of finding the file names is already done for us. The presupplied File Open and File Save dialog boxes are examples of what are called Windows common dialog boxes. The Windows operating systems supplies us with a number of these.

Another good thing is that the place where we do our file loading and saving is easy to find; it's the CPopDoc::Serialize method in PopDoc.cpp. The AppWizard has put a skeleton of the code there with TODO comments indicating where to add your code.

Before undertaking serialization, you should adjust your File dialog so that it uses a reasonable default extension for the files you want to save and open (see Sections 23.9 and 29.9).

    Part I: Software Engineering and Computer Games
    Part II: Software Engineering and Computer Games Reference