How to find the files linked (OLE) within a Word Document?

Posted on 2006-07-02
Last Modified: 2008-01-09

I have a requirement to read a range of OLE Compound File formats (including Word Documents, Excel, Powerpoint, etc) and perform the following tasks;
1) Extract a list of all files either linked or embedded to the parent document
2) Save these linked files to a specific location (or in the case of linked files, can just copy the link target to a new location)

My problem here is really in Step 1 -> I have so far been unable to find a way to access linked/embedded files within a parent document.

My current methodology is something like;

1) Call StgOpenStorageEx on the parent file and receive an IStorage pointer
2) Call StgIsStorageFile to make sure I am working with a compound storage file
3) Call IStorage->EnumElements to find the nested objects
4) Check the type of each object looking for contained STGTY_STORAGE objects
5) Try to get an IOleLink pointer from that storage?

Here is about where it falls down. No idea if my steps thus far are correct,  but I can't get an IOleLink pointer on any of the enumerated objects...

Question by:rjlohan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 11

Expert Comment

ID: 17030019
I think the problem you are having is simply that Word stores the OLE links in a record within the storage object, not as a storage object.  I can't help much with parsing those, but this might:

Hope this helps.
LVL 11

Accepted Solution

KurtVon earned 500 total points
ID: 17030026
I think you will find the information you need in the "ObjectPool" storage item.

Author Comment

ID: 17034533
That looks to be right - if I call OpenStorage on the 'ObjectPool' storage item, the sub-storages of that appear to be the actual linked items, and have storage class IDs such as {CLSID_StdOleLink} or {CLSID_Microsoft Word Document}.

Just wish I could find some documentation to be sure! :-P

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Expert Comment

ID: 17036895
I know that Word uses the object pool to create the OLE objects it links to, but I suspect documentation is going to be hard to come by just because Microsoft guards that like a state secret.

Author Comment

ID: 17039422
It certainly looks that way. I have found how to access some link types, where the sub-storage within the ObjectPool has a classID of 'CLSID_StdOleLink', but accessing other embedded content, say a Word Document embedded as 'CLSID_Microsoft Word Document' is proving quite difficult. Can't find any information about the original link file (such as paths) within the storage anywhere.
LVL 11

Expert Comment

ID: 17047791
If I remember correctly, Word doesn't use a path, but a UUID for the location of the document.  The OS (2000 and later) tracks the UUID for the location, so renaming or moving the file keeps the UUID the same, and links are much harder to break.  Try passing UUIDs inside the object to directory services to see if any produce links.

Author Comment

ID: 17048003
Can't see anywhere to find that UUID. There must be a way, Word obviously knows how to do certain things, like opening these files...

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

734 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