1.先贴上该类:
class CArchive
{
protected:
enum SchemaMapReservedRefs { objTypeArrayRef = 1 };
enum LoadArrayObjType{ typeUndefined = 0, typeCRuntimeClass = 1, typeCObject = 2 };
public:
// Flag values
enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };
CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
~CArchive();
// Attributes
BOOL IsLoading() const;
BOOL IsStoring() const;
BOOL IsByteSwapping() const;
BOOL IsBufferEmpty() const;
CFile* GetFile() const;
UINT GetObjectSchema(); // only valid when reading a CObject*
void SetObjectSchema(UINT nSchema);
// pointer to document being serialized -- must set to serialize
// COleClientItems in a document!
CDocument* m_pDocument;
// Operations
UINT Read(void* lpBuf, UINT nMax);
void EnsureRead(void *lpBuf, UINT nCount);
void Write(const void* lpBuf, UINT nMax);
void Flush();
void Close();
void Abort(); // close and shutdown without exceptions
// reading and writing strings
void WriteString(LPCTSTR lpsz);
LPTSTR ReadString(_Out_z_cap_(nMax+1) LPTSTR lpsz, _In_ UINT nMax);
BOOL ReadString(CString& rString);
public:
// Object I/O is pointer based to avoid added construction overhead.
// Use the Serialize member function directly for embedded objects.
friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);
friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);
// insertion operations
CArchive& operator<<(BYTE by);
CArchive& operator<<(WORD w);
CArchive& operator<<(LONG l);
{
protected:
enum SchemaMapReservedRefs { objTypeArrayRef = 1 };
enum LoadArrayObjType{ typeUndefined = 0, typeCRuntimeClass = 1, typeCObject = 2 };
public:
// Flag values
enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };
CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
~CArchive();
// Attributes
BOOL IsLoading() const;
BOOL IsStoring() const;
BOOL IsByteSwapping() const;
BOOL IsBufferEmpty() const;
CFile* GetFile() const;
UINT GetObjectSchema(); // only valid when reading a CObject*
void SetObjectSchema(UINT nSchema);
// pointer to document being serialized -- must set to serialize
// COleClientItems in a document!
CDocument* m_pDocument;
// Operations
UINT Read(void* lpBuf, UINT nMax);
void EnsureRead(void *lpBuf, UINT nCount);
void Write(const void* lpBuf, UINT nMax);
void Flush();
void Close();
void Abort(); // close and shutdown without exceptions
// reading and writing strings
void WriteString(LPCTSTR lpsz);
LPTSTR ReadString(_Out_z_cap_(nMax+1) LPTSTR lpsz, _In_ UINT nMax);
BOOL ReadString(CString& rString);
public:
// Object I/O is pointer based to avoid added construction overhead.
// Use the Serialize member function directly for embedded objects.
friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);
friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);
// insertion operations
CArchive& operator<<(BYTE by);
CArchive& operator<<(WORD w);
CArchive& operator<<(LONG l);