>I have another question though:
>
>CMemFile mf;
> CArchive ar( &mf, CArchive::store );
> COleServerDoc::Serialize(ar);
> mf.SeekToBegin();
> int nSize = mf.GetLength();
> BYTE* pBuffer = mf.Detach();
> CString csBase64;
> csBase64 = CMarkup::EncodeBase64( pBuffer, nSize);
>
> xml.AddChildElem("Values", csBase64);
> ar.Close();
>
>This asserts when the memory file object (mf) gets out of scope or when
>ar.Close() is called. The assertion is in CMemFile::AssertValid(), exactly
in the following line:
>
>ASSERT(m_nFileSize <= m_nBufferSize);
>
>Any idea?
You should call ar.Close() BEFORE mf.Detach(), to ensure that data is
written out to the 'file' before trying to access the memory... otherwise
you're "whipping the carpet out from underneath your feet". I believe this
is why ar.Close() causes the assert. I believe mf going out of scope causes
an assert if done before ar.Close() because it implicitly calls mf.Close(),
and in this situation the CMemFile is 'hooked' open by the CArchive, and
thus must be released by the archive before you try and close the 'file'.
It might seem wrong to close the archive before accessing the memory in
CMemFile, but it is not; closing the archive simply releases the hold on the
'file', it does not close it in any way (I'm guessing you were worried it
would close and destroy the CMemFile if you closed the archive before
Detach()?).
--
Jason Teagle
[EMAIL PROTECTED]