
Signature
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
I am building a testing tool for testing COM components that I build. I was
wanting to have the tool display a list of all COM components that have a
class supporting a particular interface e.g. ITestComponent
It's not a "must have feature", but a "would be nice feature".
If it can't be done easily, then no worries.
> Does anyone know of a way to find all COM components that implement a
> specific interface.
>
> For example, specify interface "Ixxxxxxx" or an IID and the result
> returned is an array of ProgIDs or CLSIDs.
The only way is to enumerate all the CLSIDs in the registry, instantiate
each class and then query the objects for the interface. Why you want to do
that?

Signature
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
How does OLE View do it? In OLE View I am able to open a typelib and see the
interfaces a coclass implements.
I'm guessing that it can be done some how using the ITypeInfo and ITypeLib
interfaces. Currently, I am able to get the name and CLSID of each coclass
in a typelib using those interfaces.
> Does anyone know of a way to find all COM components that implement a
> specific interface.
>
> For example, specify interface "Ixxxxxxx" or an IID and the result
> returned is an array of ProgIDs or CLSIDs.
The only way is to enumerate all the CLSIDs in the registry, instantiate
each class and then query the objects for the interface. Why you want to do
that?

Signature
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Kim Gräsman - 22 Nov 2003 14:58 GMT
Hi John,
> How does OLE View do it? In OLE View I am able to open a typelib and
> see the interfaces a coclass implements.
>
> I'm guessing that it can be done some how using the ITypeInfo and
> ITypeLib interfaces. Currently, I am able to get the name and CLSID
> of each coclass in a typelib using those interfaces.
Yeah, provided there is type information available, you can use the typelib
API to parse it. You should check out Tim Tabor's tlb2xml [1], which
generates an XML document from a typelibrary, with reasonably high fidelity.
It's probably not very useful to you in and of itself, but the source code
demonstrates a lot of typelib API goodies.
Kim
[1] http://www.cheztabor.com/tlb2xml/index.htm
John M - 23 Nov 2003 03:52 GMT
Thanks Kim. That link was useful. I have it sussed now.
> Hi John,
>
[quoted text clipped - 15 lines]
>
> [1] http://www.cheztabor.com/tlb2xml/index.htm
Alexander Nickolov - 24 Nov 2003 23:26 GMT
Weren't you interested in the opposite lookup? FYI, OleView
does not do such a lookup - from an interface to public objects
that implement it. It's easy to implement though - enumerate
all subkeys to HKCR\CLSID, instantiate the objects and query
them for the interface in question. Takes time of course...
A type library cannot solve this problem either. An interface
described in one type library may be implemented by coclasses
described in many other type libraries. Worse yet, a coclass
may not list it among its interfaces (type information is advisory
only, it's not mandatory). To top it off, a public object not described
in any type library may implement it too. Furthermore, many
interfaces are not described in type libraries at all...

Signature
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
> How does OLE View do it? In OLE View I am able to open a typelib and see the
> interfaces a coclass implements.
[quoted text clipped - 12 lines]
> each class and then query the objects for the interface. Why you want to do
> that?
Kim Gräsman - 26 Nov 2003 09:23 GMT
Alexander,
> Worse yet, a coclass may not list it among its
> interfaces (type information is advisory
> only, it's not mandatory).
Good point, I forgot to mention that.
It sounded like John was mainly interested in doing what OleView does, i.e.
listing all interfaces for the coclass mentioned in the tlb.

Signature
Best regards,
Kim Gräsman