Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an ITypeInfo pointer to get the name of the type?

Tags:

automation

com

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?

like image 353
Peter Ruderman Avatar asked Sep 19 '10 16:09

Peter Ruderman


2 Answers

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

CComBSTR typeName;
hr = typeInfo->GetDocumentation( MEMBERID_NIL, &typeName, NULL, NULL, NULL );

If you're programming in .NET, the above is conveniently performed for you by the Marshal.GetTypeInfoName method:

// using System.Runtime.InteropServices;
string typeName = Marshal.GetTypeInfoName(typeInfo);
like image 141
Peter Ruderman Avatar answered Sep 19 '22 21:09

Peter Ruderman


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.

like image 31
Richard Cook Avatar answered Sep 22 '22 21:09

Richard Cook