The following sample codes (IDL and C files) serves as an example of how to use the Save/Restore methods. In this example, class X, a subclass of WPDataFile, introduces two pieces of persistent instance data.
include wpdataf.idl
interface X : WPDataFile
{
.
.
.
implementation
{
ULONG ulA; //# Persistent instance data introduced by class X
PSZ pszB;
wpSaveState: override; //# To save your data
wpRestoreState: override; //# To restore your data
wpInitData: override; //# To supply default values for your data
};
};
The following sample code shows the source code for X:
BOOL SOMLINK x_wpSaveState(X * somSelf)
{
_wpSaveLong(somSelf, "X", 1, _ulA);
_wpSaveString(somSelf, "X", 2, _pszB); // Key is X and 1 for _ulA
return parent_wpSaveState(somSelf); // Key is X and 2 for _pszB
}
.
.
.
BOOL SOMLINK x_wpRestoreState(X * somSelf, ULONG ulReserved)
{
ULONG ulSize;
// Key is X and 1 for _ulA
_wpRestoreLong(somSelf, "X", 1, &_ulA);
// Key is X and 2 for _pszB
_wpRestoreString(somSelf, "X", 2, &_pszB, &ulSize);
return parent_wpRestoreState(somSelf, ulReserved);
}
.
.
.
BOOL SOMLINK x_wpInitData(X * somSelf)
{
BOOL rc;
rc = parent_wpInitData(somSelf);
_ulA = 1001;
_pszB = "hello";
return rc;
}
Note: Some of the save and restore methods are used in a complete program that is illustrated in Sample Code for Setup/Cleanup Methods.