tags:

views:

31

answers:

2

Should be a simple question, but searching the documentation is driving me nuts. Suppose I have an ITypeInfo pointer for a coclass or an interface. How do I get the name of that class or interface?

A: 

The short answer: you can't using ITypeInfo. You can obtain the prog ID of class using the Win32 ProgIDFromCLSID API. In COM the name of the underlying C++, Visual Basic or .NET class implementing the COM interface or co-class is practically meaningless. Only interface IDs, class IDs and programmatic IDs have any significance beyond the source code of your co-class's implementation: only these can be used for activating COM objects using CoCreateInstance et al and runtime casting using QueryInterface.

Richard Cook
Well, suppose I have a valid reason for this (but maybe I don't). Anyway, are you sure that it's impossible? It seems like the various Microsoft type library utilities are able to enumerate this information. How do they do it?
Peter Ruderman
Well, quite often the prog ID is chosen so that it is the same as or similar to the C++ class name - but this is only a convention. Most of the type library utilities either enumerate information in the Windows registry or in .tlb files all of which deal exclusively with class IDs, interface IDs and prog IDs. Ultimately it is entirely down to the implementation of `DllGetClassObject` in your COM server DLL to associate these COM values with your C++ class.
Richard Cook
A: 

Ok. It did turn out to be pretty simple. You just need to call the GetDocumentation() method with the member id set to MEMBERID_NIL. Like so:

CComBSTR typeName;
hr = typeInfo->GetDocumentation( MEMBERID_NIL, &typeName, NULL, NULL, NULL );
Peter Ruderman
Are you sure that this doesn't just return the content of the [helpstring] attribute associated with a co-class? I'm happy to proved wrong!
Richard Cook
Furthermore, the underlying implementation of a COM co-class might not even be any kind of class at all (see http://www.codeproject.com/KB/COM/com_in_c1.aspx for an example of how to write a COM object in plain C). The notion of "class" is entirely language-dependent and I doubt that you can rely on the GetDocumentation method to obtain this information.
Richard Cook
Remember that my question is dealing with automation. This is the process of calling methods on an interface through COM and is completely independent of the implementation of those methods. The coclasses and interfaces in question have associated metadata (accessible through ITypeInfo), and this does include their names. In any case, thanks for your help. I do appreciate it!
Peter Ruderman