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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now