CArchive and CompoundFile
-
the Document is a CompoundFile ( include: ole, image file, ... ) ----------------------------------------------------------- I can open or save Document( 1: CMyDoc::Serialize) but how can I load file to CMfSet Directly ( 2: CMfSet::Open ) 1. ----------------------------------------- void CMyDoc::Serialize(CArchive& ar) { // m_curMfSet is member var of CMyDoc : ( CMfSet m_curMfSet; ) m_curMfSet.Serialize(ar); COleDocument::Serialize(ar); ... }; 2. ----------------------------------------- class CMfSet : public CObject { DECLARE_SERIAL(CMfSet) public: // consturct or disconturct CMfSet(); ~CMfSet(); public: BOOL Open(LPCTSTR lpszFilename); // ... }; BOOL CMfSet::Open(LPCTSTR lpszFilename) { CFile f; if( !f.Open( lpszFilename, CFile::modeRead) ) return FALSE; TRY { char buf[4096]; CArchive ar(&f, CArchive::load, 4096, buf); Serialize(ar); // It is sure error, but I don't know how correct it } CATCH_ALL(e) { return FALSE; } END_CATCH_ALL return TRUE; }; Thank you!
-
the Document is a CompoundFile ( include: ole, image file, ... ) ----------------------------------------------------------- I can open or save Document( 1: CMyDoc::Serialize) but how can I load file to CMfSet Directly ( 2: CMfSet::Open ) 1. ----------------------------------------- void CMyDoc::Serialize(CArchive& ar) { // m_curMfSet is member var of CMyDoc : ( CMfSet m_curMfSet; ) m_curMfSet.Serialize(ar); COleDocument::Serialize(ar); ... }; 2. ----------------------------------------- class CMfSet : public CObject { DECLARE_SERIAL(CMfSet) public: // consturct or disconturct CMfSet(); ~CMfSet(); public: BOOL Open(LPCTSTR lpszFilename); // ... }; BOOL CMfSet::Open(LPCTSTR lpszFilename) { CFile f; if( !f.Open( lpszFilename, CFile::modeRead) ) return FALSE; TRY { char buf[4096]; CArchive ar(&f, CArchive::load, 4096, buf); Serialize(ar); // It is sure error, but I don't know how correct it } CATCH_ALL(e) { return FALSE; } END_CATCH_ALL return TRUE; }; Thank you!
I had solved it: CRuntimeClass *pRuntimeClass = RUNTIME_CLASS(CMyDoc); CMyDoc *pDoc = (CMyDoc *)(pRuntimeClass->CreateObject()); if( pDoc->OpenDocument(lpszFilename) ) pSet->FromOther( pDoc->GetMfSet() ); delete pDoc; ... ------------------------------------------------------ any advance soultion?( if you have time, please tell me the answer) Thank you!