This is exactly the kind of thing I'm looking for. I have something like this:
CMyDocument:public CDocument
{
...
CMyBigObject1 m_object1;
CMyBigObject2 m_object2;
.
.
.
CMyBigObjectN m_objectN;
...}
Each CMyBigObjectN type has multiple CObLists and other variable storage types and so I'd like to break each CMyBigObjectN into a different stream so I don't have to read in the whole file. Is this what you mean when you ask about document properties in different streams? If it is, I'd really like to see your code. Thanks for the help.
Main Topics
Browse All Topics





by: RONSLOWPosted on 1998-04-07 at 21:39:23ID: 1317536
Do you want document properties in separate streams? I have sample code for that if you want.
age functions of your document and pass m_lpRootStg as the lpRootStg param.
LPSTORAGE lpRootStg, LPCTSTR szName) { Stg, szName, ::shareExc lusive|CFi le::modeCr eate, &fe)) nd) ArchiveExc eption::ba dSchema); _cause, fe.m_lOsError); );
YIFCURRENT );
(LPSTORAGE lpRootStg, LPCTSTR szName) { g, szName, CFile::modeRead|CFile::sha reExclusiv e, &fe)) { 1); // last schema without schema support nd) { _cause, fe.m_lOsError);
);
Also here is some sample code to serialize a CObject derived object to/from a stream. You would call this in your SaveToStorage/ReadFromStor
bool CMyObject::WriteToStorage(
COleStreamFile file;
CFileException fe;
if (!file.CreateStream(lpRoot
CFile::modeReadWrite|CFile
{
if (fe.m_cause == CFileException::fileNotFou
AfxThrowArchiveException(C
else
AfxThrowFileException(fe.m
}
// save to Contents stream
CArchive saveArchive(&file, CArchive::store | CArchive::bNoFlushOnDelete
saveArchive.m_pDocument = NULL;
saveArchive.m_bForceFlat = FALSE;
TRY
{
Serialize(saveArchive);
saveArchive.Close();
file.Close();
// commit the root storage
SCODE sc = lpRootStg->Commit(STGC_ONL
if (sc != S_OK)
AfxThrowOleException(sc);
}
CATCH_ALL(e)
{
file.Abort(); // will not throw an exception
// CommitItems(FALSE); // abort save in progress
saveArchive.Abort();
THROW_LAST();
}
END_CATCH_ALL;
return true;
}
bool CMyObject::ReadFromStorage
// open stream
COleStreamFile file;
CFileException fe;
if (!file.OpenStream(lpRootSt
QSchema::SetSchemaDirect(2
if (fe.m_cause == CFileException::fileNotFou
return false;
} else {
AfxThrowFileException(fe.m
}
}
// load it with CArchive (loads from Contents stream)
CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete
loadArchive.m_pDocument = NULL;
loadArchive.m_bForceFlat = FALSE;
TRY
{
Serialize(loadArchive); // load main contents
loadArchive.Close();
file.Close();
}
CATCH_ALL(e)
{
file.Abort(); // will not throw an exception
// DeleteContents(); // removed failed contents
loadArchive.Abort();
THROW_LAST();
}
END_CATCH_ALL;
return true;
}