使用 IDL 定义纯基类
当我在 IDL 中定义一个不派生自任何内容的接口时,MIDL 预编译器会发出这样的警告 (Visual C++ 2008):
警告 MIDL2271:[对象] 接口必须从另一个 [对象] 接口派生,例如 IUnknown (...)
如果我从不是从 IUnknown 派生的另一个接口派生我的接口,MIDL 将失败:
错误 MIDL2257:只有 IUnknown 可以用作根接口(...)
现在,我的问题:这是 COM 或 MIDL 预编译器的限制吗?
我最近一直在查看 D3D10 标头,d3d10.h 显然是使用 IDL 生成的(MIDL 为此效果添加了注释)。 所有接口都以某种方式派生自 IUnknown。
但是,外围设备标头(d3d10shader.h、d3d10effect.h 等)包含手动定义的 COM 接口,其中一些接口会触发此处描述的警告或错误。 我只能假设他们必须手动定义它们以避免这些限制。
我对吗? 为什么 MIDL 阻止纯接口?
When I define an interface in IDL which does not derive from anything, the MIDL precompiler warns as such (Visual C++ 2008) :
warning MIDL2271 : [object] interfaces must derive from another [object] interface such as IUnknown (...)
And if I derive my interface from another which does not derive from IUnknown, MIDL fails :
error MIDL2257 : only IUnknown may be used as the root interface (...)
Now, my question : Is this a limitation in COM or the MIDL precompiler?
I have been looking at the D3D10 headers recently, and d3d10.h obviously has been generated using IDL (MIDL adds a comment to this effect). And all the interfaces derive from IUnknown in one way or another.
However, the peripheral headers (d3d10shader.h, d3d10effect.h, etc.) contain manually defined COM interfaces, some of which would trigger the warning or the error described here. I can only assume they had to define them manually to avoid those limitations.
Am I right? Why does the MIDL prevent pure interfaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是从 IUnknown 派生的接口不是 COM。 这是允许内存管理和接口发现的基本构建块。
可能存在不是从 IUnknown 派生的接口。 然而它们不是 COM,它们只是一个普通的指针。
An interface that does not derive from IUnknown is not COM. This is the basic building bloc that allow memory managing and interface discovery.
There might be interfaces not deriving from IUnknown. However those are not COM, they are just a normal pointer.