开发者

Weird namespace addition when importing a typelib

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 cal开发者_如何学Pythonl 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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜