Serialization is the process of reading or writing an object to or from a stream. This stream can be a storage medium like a disk file, stream or socket file. Serialization is necessary for situations where it is desired to maintain the state of an object (object of C++ classes or structures). Program can store the data members of the object in file and exit if needed. Later it can load the members in the same way it was saved and thus maintain the same state of the object as before. Serialization is not limited to disk file. File stream can be in the form of network socket or byte stream for serial line or in any other form.
Need of Serialization
An object with members of primitive types such as char, short, int, float, or double can be stored with easy file operations. Members are saved serially one by one and can be retrieved in the same sequence. Saving an C++/MFC object is some what different from this traditional structured approache. MFC class object can contain another objects like CString, CArray. These objects are of variable lenghts. Again we need to takecare both save and restore of parent class before do the same for current class. MFC defines an uniform way to save and restore any object to or from file stream and this support is there from top level CObject in the MFC hiararchy. Any object that supports Serialization should call the parent class Serialization routine before processing its own members. Thus the entire hiararchy state members of the object are saved and restored. MFC also defines uniform ways to CString, CArray and other variable length objects.
It starts with the CObject class that is the ancestor to most MFC classes, which is equipped with a Serialize() member function. The class should declare with the macros DECLARE_SERIAL(< class name >) and also should add implement macro IMPLEMENT_SERIAL(< class name >, < parent class name >, < Schema version >). The class should implement Serialize(CArchive&) routine and it should save and restore class members in this routine. Let us look into a simple example by creating a new MFC project. Here we declared a class called CStudent to store and retrieve fields of a student. It contains standard, enrollment number, name, marks and age. This demo application is based on a dialog box which retrieves these files when "Open" button is pressed. It reads and shows these fields. User can enter new values and save those with "Save" button.
About our authors: Team EQA
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Draw on printer Memory leaks