CArchived CDocument -> Structured Storage

I've got an SDI whose CDocument I'd like to break apart using structured storage. I think that I need to use COleStreamFile, but I can't find any examples of how to break apart the document's variables into different streams. (This is possible, right?) My question is really for a referral: Besides Kruglinski, can anyone point me in the direction of sample code/explanations which demonstrate how to do this? For bonus points, anyone have a snippet? Thanks for any help.

Do you want document properties in separate streams? I have sample code for that if you want.

Also here is some sample code to serialize a CObject derived object to/from a stream. You would call this in your SaveToStorage/ReadFromStorage functions of your document and pass m_lpRootStg as the lpRootStg param.

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.

I mean that I write out OLE document properties to the approriate stream (as opposed to the "content" stream that MFC writes your serialized data to). I also write out (using the code above) my own data stored in a heirachy of lists.

What I would do for your code is
void CMyDocument::SaveToStorage(CObject* pObject) {
m_object1.WriteToStorage(m_lpRootStg,"Object1");
m_object2.WriteToStorage(m_lpRootStg,"Object2");
...
m_objectN.WriteToStorage(m_lpRootStg,"ObjectN");
CDocument::SaveToStorage(pObject);
}

where WriteToStorage method for each object is as per my answer above. You simply use the same Serialize method as you'd use for standard MFC serializing.

Similar for reading from storage. Of course, for reading, you don't need to read all the storages in, nor in the same order that you wrote them as each is independant.

pObject is usually NULL (if you want to save the whole document) - but COleServerItem also uses this to save itself, in which case it calls the SaveToStorage of its associated document and passes itself (this) as the pObject to the document.

Yes - SaveToStorage is an (undocumented) COleDocument function and is called by OnSaveDocument to do the saving. The default implementation is very much like my code above but is hard coded to write to the stream "Contents". I simply took the MFC code and changed it a little to allow me to write to a nominated stream.

Look in the MFC source to see how it is called (that's what I did).

A COM book may not help much with MFC environment .. they are usually straight C++

Good thing mail interrupts IE4 (you saved me some money). I now just need to change CMyDocument's base class to COleDocument and I've solved a problem I should have foreseen in the planning stage. (The worst kind.)

If not COM, could you recommend a book on OLE & MFC? Or is the MFC source sufficient for this problem?

I haven't read many book on OLE/MFC - I do have a book on COM and have attended some seminars on COM. Most of what I know comes from reading the docco, then looking at source code an smaples to work out what the docs really meant and find out how they work.

So, I cannot really recommend a book for you.

But the MFC source was sufficient for me as I just looked at the source code to see how files were saved to OLE structured storage and adapted what I needed from there.

Featured Post

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes. I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.
Introductio…

Introduction:
Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers). Error trapping with try..catch to help the code run even if something goes wrong.
Continuing from the seve…

Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message. In the To field, type your recipient's fax number @efaxsend.com.
You can even send a secure international fax — just include t…