0

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?

sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • FYI, ocidl.idl imports oaidl.idl, oaidl.dil imports objidl.idl, and objidl.idl imports unknwn.idl. So you just need to import ocidl.idl. –  Feb 06 '15 at 21:08

1 Answers1

0

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 蒋晟
  • 15,125
  • 2
  • 28
  • 46