Richard H.Administrator
(KiX Supporter)
2004-09-15 05:24 PM
How to find typelib from object...

I'm working on a method of automatically importing constants and enums.

I'm looking for a way to get from the object to the typelib, for example
"word.document" -> "c:\program files\Microsoft Office\Office10\MSWORD.OLB"

I just can't see how to associate the registry entries.


LonkeroAdministrator
(KiX Master Guru)
2004-09-15 06:11 PM
Re: How to find typelib from object...

well...
.olb is not typelib, is it?


ShawnAdministrator
(KiX Supporter)
2004-09-15 07:20 PM
Re: How to find typelib from object...

that be it i think

word.document\CLSID = {00020906-0000-0000-C000-000000000046}

HKEY_CLASSES_ROOT\CLSID\{00020906-0000-0000-C000-000000000046}\TYPELIB =
{00020905-0000-0000-C000-000000000046}

HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.2\0\win32\default =
C:\Program Files\MSOffice\Office10\MSWORD.OLB

-Shawn


LonkeroAdministrator
(KiX Master Guru)
2004-09-15 08:13 PM
Re: How to find typelib from object...

k, what that olb stands for?
office library?


ShawnAdministrator
(KiX Supporter)
2004-09-15 08:48 PM
Re: How to find typelib from object...

guess so,

but I don't think we've answered Richard's question ... the problem is - given any PROGID, determine the typelib, no matter what the class. Think they're are a few more steps we're missing - that 8.x keyname stuff is specific to Office, must be other routes to this value, that aren't package specific.


LonkeroAdministrator
(KiX Master Guru)
2004-09-15 09:01 PM
Re: How to find typelib from object...

well, I can't comment as don't have that stuff.
thus, it's not specific to office but specific to office10 (xp or what the heck it was)


ShawnAdministrator
(KiX Supporter)
2004-09-15 09:27 PM
Re: How to find typelib from object...

Here's a pretty good knowledgebase:

INFO: Registry Entries Made by an ActiveX Component

But checked quickly, think this office stuff breaks the rules a little bit - not totally sure.

Btw - one of the KB references is to Dale Rogerson's "Inside COM" book ... he's the MS COM guru and this is (debatably) the "COM Bible", kinda like the K&R of COM.

-Shawn


Stevie
(Starting to like KiXtart)
2004-09-16 05:25 AM
Re: How to find typelib from object...

These are the basic steps I'm using in AdminScriptEditor to provide COM "ScriptComplete", which of course requires getting the typelib from a known progid:

  • Call CLSIDFromProgID to get the CLSID corresponding to the Prog ID
  • Read HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\Typelib key
  • If the above value exists, read its default value. This value will be the GUID representing the typelibrary.
  • Once you get the GUID representing the typelibrary, read the default value of HKEY_CLASSES_ROOT\Typelib\<GUID representing the
    typelibrary>\<Version>\<Sub Version>\win32
  • This default value will be the full path to the typelibrary
  • If you do not find the Typelib key under HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component> in Step 2, read the default value of one of the following:
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\InprocServer (for 16 bit DLLs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\InprocServer32 (for 32 bit DLLs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\LocalServer (for 16 bit EXEs)
    HKEY_CLASSES_ROOT\CLSID\<CLSID of the Component>\LocalServer32 (for 32 bit EXEs)


Like Shawn points out, though, this procedure doesn't work in every case. The immediate exceptions that come to mind are the office exe's and several of the VBScript-specific ProgIDs. This should cover the vast majority, though.

I actually contacted MS COM development team on this and they told me there's no way to guarantee the result with this method. If you're asking specifically about how to absolutely account for these exception types, to my knowledge the only way to do it is a less-than-ideal hack. In your example, however, IIRC, the result is the same path and filename except the extension is .exe. So, if the resulting file is an .exe you can check the same directory for an .olb file with the same name and if you find it query the typelib from there. Again, certainly not an ideal solution, but will get you close. IIRC, some of the Office exe and olb files were not even in the same directory, but I can't remember which apps and Office versions those were--so in those cases there's no resolution.

If you find something that is a bit more concrete I would love to know about it.

HTH


LonkeroAdministrator
(KiX Master Guru)
2004-09-16 11:56 AM
Re: How to find typelib from object...

k, looking in my typelib branch, this 8.2 stuff you talking about is nothing unusual.
all typelibs give somekind of version number there.
so, what is the difficulty in that?


Richard H.Administrator
(KiX Supporter)
2004-09-17 10:13 AM
Re: How to find typelib from object...

Quote:

k, looking in my typelib branch, this 8.2 stuff you talking about is nothing unusual.
all typelibs give somekind of version number there.
so, what is the difficulty in that?




Getting the version number so that you can read the right key

Sorry I haven't updated, had to be somewhere else yesterday.

I thought that I'd gone through all the GUID / key combinations and hadn't got a consistantly working result.

I'll work through the suggestions and let you know how I get on.


LonkeroAdministrator
(KiX Master Guru)
2004-09-17 01:41 PM
Re: How to find typelib from object...

well, mostly there is only one version, that makes it rare to have problems with it.
k, have to dig deeper...