16,471
社区成员
发帖
与我相关
我的任务
分享
COleStreamFile file;
CFileException fe;
if (!file.OpenStream(m_lpRootStg, _T("Contents"),
CFile::modeRead|CFile::shareExclusive, &fe) &&
!file.CreateStream(m_lpRootStg, _T("Contents"),
CFile::modeRead|CFile::shareExclusive|CFile::modeCreate, &fe))
{
if (fe.m_cause == CFileException::fileNotFound)
AfxThrowArchiveException(CArchiveException::badSchema);
else
AfxThrowFileException(fe.m_cause, fe.m_lOsError);
}
// load it with CArchive (loads from Contents stream)
CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete);
loadArchive.m_pDocument = this;
loadArchive.m_bForceFlat = FALSE;
TRY
{
if (file.GetLength() != 0)
Serialize(loadArchive); // load main contents
loadArchive.Close();
file.Close();
}
CATCH_ALL(e)
{
file.Abort(); // will not throw an exception
DeleteContents(); // removed failed contents
NO_CPP_EXCEPTION(loadArchive.Abort());
THROW_LAST();
}
END_CATCH_ALL