开发者

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

开发者 https://www.devze.com 2023-01-16 14:42 出处:网络
Should be a simple question, but searching the documentation is开发者_如何学Python driving me nuts.Suppose I have an ITypeInfo pointer for a coclass or an interface.How do I get the name of that class

Should be a simple question, but searching the documentation is开发者_如何学Python 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?


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消