Extract CLSID from binary file savewith TOLEContainer.SaveToFile

Giganews Newsgroups
Subject: Extract CLSID from binary file savewith TOLEContainer.SaveToFile
Posted by:  …@Spam.com
Date: 26 Mar 2006

Hi,

I have the content of a TOLEContainer (that can be anything e.g. Word doc,
Excel, Bitmap, etc depending on the user of my app) that can be saved to a
file via TOLEContainer.SaveToFile(Filename). Now, I need my application to be
able to get the ClassID of this saved contents.

I know I could do:

Function GetClassIDFromFile(Const Filename : String) : TCLSID;
Begin
    OLEContainer.LoadFromFile(Filename)
    Result := ProgIDToClassID(OLEContainer.OLECLassName);
End;

However, this obliges me to have an OLEContainer in which to load the document
file (which slows down my app because I need to extract this ClassID from
several tens of documents), then read the ClassID from it.
Also, because GetClassIDFromFile in my app will be in a unit without form, I
have no parent form to place OLEContainer. I'd need to create a hiden form as
parent for my OLEContainer control and I don't really want to do this (a bit
ugly as a solution).

Would there be any way by reading directly the binary data of the file to get
its ClassID? It's surely here somewhere in the binary data, probably in some
data header so that when it's loaded in an OLEContainer, it can activate its
application but I don't know the structure of the binary file. Has anybody got
a method to do so?

Thanks,
David.

Replies