how to read and extract information from OLE file format ?

Hi all,

m Muhammad Azeem,

I m working on OLE file format. i had a compound document which contains the data of a GIF. I was able to extract the JPG information from that document (which was residing actually in the "Ole10Native" stream of structured storage). but now compound document contains any type of data (doc, jpg etc). i want that i read binary data from the compound document's streams and convert it to native format. but i don't know that in which streams in the compound document the data resides. i m using VC as programming language

is any body has answer for it,

thanx in advance,
Muhammad Azeem
Who is Participating?

Improve company productivity with a Business Account.Sign Up

_ys_Connect With a Mentor Commented:
> that means there is no pre-defined way
Yep, that's right. Every application can store it whatever way they see fit.

> is there a way to find header and footer of a valid MSWord file
MSWord has it's object model just for this kind of thing. Although I'm afraid I can't help you with it - never delved into it that much to be confident with an answer on the topic.

Pop the question into the relevant MSWord section. You'll probably get an answer in VBA, but this should be straightforward to convert to C++. And that I can help you with.
The following code simply enumerates all steams/storages within a simple compound document.
#include "objBase.h"

#include <iostream>
#include <string>

int main(int argc, char* argv[])
//  Initialise COM/OLE

//  Open a compound storage document
    IStorage *pStorage = NULL;
    HRESULT hr = StgOpenStorageEx(
        0, NULL,

    if (SUCCEEDED(hr))
        STATSTG stat;
        memset(&stat, 0, sizeof(STATSTG));
        pStorage->Stat(&stat, STATFLAG_DEFAULT);

    //  output the storage name (in this case the complete file path)
        std::wcout << stat.pwcsName << std::endl;

    //  enumerate the contained elements
        IEnumSTATSTG *pEnumSTATSTG = NULL;
        if (SUCCEEDED(hr = pStorage->EnumElements(0, NULL, 0, &pEnumSTATSTG)))
            STATSTG rgStat[1];
            memset (&rgStat[0], 0, sizeof(STATSTG));

            long lCount = 0;
            while (SUCCEEDED(hr) && (S_FALSE != hr))
                hr = pEnumSTATSTG->Next(1, &rgStat[0], NULL);

                if (SUCCEEDED(hr) && (S_FALSE != hr))
                //  output their ordinal (type) - name
                    std::wcout << lCount << L" (" << rgStat[0].type << L") - " << rgStat[0].pwcsName << std::endl;

                // * it type is 1 we could recurse into it's storage elements *

                //  don't forget to free STATSTG's memory
                    memset (&rgStat[0], 0, sizeof(STATSTG));
                else std::cout << "Failed to enumerate! -> " << hr << std::endl;

        else std::cout << "Failed to obtain enumerator! -> " << hr << std::endl;

    //  don't forget to free STATSTG's memory
    else std::cout << "Failed to open stream! -> " << hr << std::endl;


    return 0;

The compound document was a simple Word document with text only. It produced the following output:
1 (2) - 1Table
2 (2) - &#9786;CompObj
3 (1) - ObjectPool
4 (2) - WordDocument
5 (2) - &#9827;SummaryInformation
6 (2) - &#9827;DocumentSummaryInformation
Failed to enumerate! -> 1
Press any key to continue

ObjectPool would be of particular interest [type (1) indicates it's another storage element]. The same code could be made to recursively look at all storages within it's compounded self.

HTH. Any further questions feel free to ask.
MuhammadAzeemAuthor Commented:
HI _ys_,

thank u very much for ur help, but my scenario is little differnt,
i m having IBM lotus notes database and an embedded object in that database. (this embedded object is basically a word file). and i m using an IBM provided API to get this embedded object. this API give me the object as a compound document. (say it "abc.ole" document). and this document is different from word document (though both are compound documents).

i explored the binay of word document and found that this binary actually exists in the streams of abc.ole document but is scattered across different streams. i also believe that API m using is not making its custom streams but using a standard way to create streams.

so i want to know that when an document which is already a compound document is embedded into some document container then which information of comound document is placed in which streams.

thanx for ur help
> so i want to know that when an document which is already a compound document is embedded into some document container then which information of comound document is placed in which streams.

As there's no standard for compound documents it's near impossible to predict.

Where the API returns an IStorage pointer the above code sample can provide you with the entire heirarchy of contained elements, even if they be themselves embedded compound documents [simply make the code recursive].

Once you have this heirarchy trial and error will allow you to determine which streams are the inportant ones. Also, between versions, the internal structure of compound documents is subject to change.
MuhammadAzeemAuthor Commented:
thanx again _ys_ ,

that means there is no pre-defined way (way of inserting embedded object's data into compound document's streams) when we embed an object into compound document using OleCreateFromFile() and OleSave() etc. APIs.

dear i would bother u last time, then is there a way to find header and footer of a valid MSWord file so that i can extract my concerning data from the streams of compound document and mix it with the header and footer to produce a valid MSWord Doc file.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.