使用 Visual Studio 添加 COM 引用会重命名 Interop Assembly 中的接口
我添加一个 C++ COM dll 作为对 C# 项目 (Visual Studio 2008) 的引用。 VS 添加了引用,但生成的互操作库并未反映原始 typelib (.idl) 定义中的命名。我的库定义如下:
[
uuid(...),
helpstring("MyLib")
]
library MyLib
{
[
uuid(...),
helpstring("MyCom CoClass")
]
coclass MyComCoClass
{
[default] interface IMyInterface;
interface IMyInheritedInterface;
interface IMyBaseInterface;
};
}
因此,IMyInterface 继承自 IMyInheritedInterface,而 IMyInheritedInterface 又继承自 IMyBaseInterface。我希望添加此 COM 的 .dll 后所有这些接口都可用。在 VS 为上面的类型库生成的互操作程序集中,IMyInterface 变为 MyInterface。为什么?有办法解决吗?
谢谢
I'm adding a C++ COM dll as a reference to a C# project (Visual Studio 2008). VS adds the reference however the generated interop library does not reflect the naming in the original typelib (.idl) definition. Here's what my library definition looks like:
[
uuid(...),
helpstring("MyLib")
]
library MyLib
{
[
uuid(...),
helpstring("MyCom CoClass")
]
coclass MyComCoClass
{
[default] interface IMyInterface;
interface IMyInheritedInterface;
interface IMyBaseInterface;
};
}
So, IMyInterface inherits from IMyInheritedInterface which in turns inherits from IMyBaseInterface. I want all of these interface available when this COM's .dll is added. In the interop assembly VS generates for the typelib above, IMyInterface becomes MyInterface. Why and is there a way around it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当接口是组件类的默认接口并且仅由该组件类使用时,typelib 导入器会执行此操作。
因此,一种解决方法是向您的类型库添加另一个虚拟组件类,并使 IMyInterface 也成为它的默认接口。
The typelib importer does that when an interface is the default interface for a coclass and it's only used by that coclass.
So one workaround is to add another dummy coclass to your typelib and make IMyInterface the default interface for that too.