导入类型库时添加奇怪的命名空间
我想向我的 COM 接口添加一个接受 IStream*
的方法。以下是 idl 摘录:
import "oaidl.idl";
import "ocidl.idl";
import "objidl.idl";//IStream is declared in this .idl file
[
uuid(uuidhere),
version(1.0)
]
library MyLibrary
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
object,
uuid("interfaceid"),
dual,
nonextensible,
oleautomation,
hidden
]
interface IMyInterface : IUnknown {
HRESULT LoadStream( [in] IStream* stream );
HRESULT LoadUnknown( [in] IUnknown* unkn );
};
}
我编译 .idl
文件并在另一个项目中导入 typelib。
当我查看 OLEView 文件中的 .tlb
时,我发现 IStream
在我的类型库中声明,但 IUnknown
没有声明。这会导致问题 - 当我尝试在另一个项目中调用 IMyInterface::LoadStream()
时,C++ 表示无法将 IStream*
转换为 MyLibrary::IStream*
。同时它不会抱怨 IUnknown。
为什么 MIDL 将 IStream 定义放在类型库中而不将其视为全局定义?
I want to add a method accepting IStream*
to my COM interface. Here's the idl excerpt:
import "oaidl.idl";
import "ocidl.idl";
import "objidl.idl";//IStream is declared in this .idl file
[
uuid(uuidhere),
version(1.0)
]
library MyLibrary
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
object,
uuid("interfaceid"),
dual,
nonextensible,
oleautomation,
hidden
]
interface IMyInterface : IUnknown {
HRESULT LoadStream( [in] IStream* stream );
HRESULT LoadUnknown( [in] IUnknown* unkn );
};
}
I compile the .idl
file and import the typelib in another project.
When I review the .tlb
in OLEView file I see that the IStream
is declared inside my typelib but IUnknown
is not. This causes problems - when I try to call IMyInterface::LoadStream()
in another project C++ says it can't convert IStream*
to MyLibrary::IStream*
. In the same time it doesn't complain about IUnknown.
Why does MIDL put IStream definition inside the typelib and not treat it as a global definition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两个 IStream,一个是全局的(在 objidl.idl 中声明),另一个在 MyLibrary 命名空间中(在 idl 中声明)。删除 MyLibrary 命名空间中的一个。
如果您计划支持脚本客户端,我建议您还公开 IDispatch 接口,因为脚本语言不支持 IStream。
You have two IStreams, one global (declared in objidl.idl), another in the MyLibrary namespace (declared in your idl). Remove the one in the MyLibrary namespace.
If you plan to support script clients, I suggest you also expose an IDispatch interface as IStream isn't supported by script languages.