how to read and extract information from OLE file format ?

Posted on 2004-04-29
Last Modified: 2013-11-25
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
Question by:MuhammadAzeem
  • 3
  • 2

Expert Comment

ID: 10953066
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.

Author Comment

ID: 10956979
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

Expert Comment

ID: 10959840
> 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.

Author Comment

ID: 10961050
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.


Accepted Solution

_ys_ earned 500 total points
ID: 10984639
> 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.

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 249
best sources to up-to-date in C++? 8 91
Need more details 5 168
SSRS Deployment problem 5 67
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question