枚举通过C# COM Interop实现的COM接口列表
我正在查询一个 MFC 实现的 COM 对象,该对象的实现如下:
class CA :
public MfcComLib::IA
{
...
};
class CB :
public MfcComLib::IB
{
...
};
class ATL_NO_VTABLE CExposedCoClass :
public CComObjectRootEx<CComSingleThreadModel>,
public CA,
public CB
{
public:
BEGIN_COM_MAP(CExposedCoClass )
COM_INTERFACE_ENTRY(MfcComLib::IA)
COM_INTERFACE_ENTRY(MfcComLib::IB)
END_COM_MAP()
在 C# 端,我收到一个 IUnknown ptr,它作为对象出现。我已经导入了 TypeLib 并获得了接口 MfcComLibLib.IA,但是当我进行强制转换时,由于接口未实现而导致失败。
有没有办法查询 IUnknown 指针来发现对象上实际实现了哪些接口?
I'm querying an MFC implemented COM object that is implemented as follows:
class CA :
public MfcComLib::IA
{
...
};
class CB :
public MfcComLib::IB
{
...
};
class ATL_NO_VTABLE CExposedCoClass :
public CComObjectRootEx<CComSingleThreadModel>,
public CA,
public CB
{
public:
BEGIN_COM_MAP(CExposedCoClass )
COM_INTERFACE_ENTRY(MfcComLib::IA)
COM_INTERFACE_ENTRY(MfcComLib::IB)
END_COM_MAP()
On the C# side I'm receiving an IUnknown ptr which comes through as an object. I've imported the TypeLib and have gotten the interface MfcComLibLib.IA but when I cast I get a failure because of the interface not being implemented.
Is there a way to query the IUnknown pointer to discover what interfaces are actually implemented on the object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与使用托管接口的方式相同。您可以使用 C#
is
或as
运算符。 CLR 会在底层将其映射到 QueryInterface 调用。Same way as you do with managed interfaces. You use the C#
is
oras
operators. The CLR will under the hood map that to QueryInterface calls.