views:

107

answers:

1

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?

A: 

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.

Sheng Jiang 蒋晟
That's what I don't get. What exactly do I do to remove the in-typelib declaration?
sharptooth
remove the IStream declaration from idl.
Sheng Jiang 蒋晟
If I remove import "objidl.idl" the behaviour remains the same. What else can I do?
sharptooth
remove the IStream declaration interface IMyInterface : IUnknown { HRESULT LoadStream( [in] IStream* stream ); HRESULT LoadUnknown( [in] IUnknown* unkn ); };
Sheng Jiang 蒋晟
I don't declare IStream, I only use it to specify the method parameter.
sharptooth

related questions