views:

118

answers:

1

hi

I have a COM object that takes needs to take a stream from a C# client and processes it. It would appear that I should use IStream. So I write my idl like below. Then I use MIDL to compile to a tlb, and compile up my solution, register it, and then add a reference to my library to a C# project.

Visual Studio creates an IStream definition in my own library. How can I stop it from doing that, and get it to use the COMTypes IStream? It seems there would be one of 3 answers: add some import

  • to the idl so it doesn't redeclare IStream (importing MSCOREE does that, but doesn't solve the C# problem)
  • somehow alias the IStream in visual studio - but I don't see how to do this.
  • All my thinking i s completely wrong and I shouldn't be using IStream at all

help...thanks

[
  uuid(3AC11584-7F6A-493A-9C90-588560DF8769),
  version(1.0),
]
library TestLibrary
{

  importlib("stdole2.tlb");

  [
    uuid(09FF25EC-6A21-423B-A5FD-BCB691F93C0C),
    version(1.0),
    helpstring("Just for testing"),
    dual,
    nonextensible,
    oleautomation
  ]
  interface ITest: IDispatch
  {
    [id(0x00000006),helpstring("Testing stream")]
    HRESULT _stdcall LoadFromStream([in] IStream * stream, [out, retval] IMyTest ** ResultValue);
  };

  [
    uuid(CC2864E4-55BA-4057-8687-29153BE3E046),
    noncreatable,
    version(1.0)
  ]
  coclass HCTest
  {
     [default] interface ITest;
  };

};
A: 

This doesn't need fixing, the interop wrapper created from the type library will be fine. The ComTypes.IStream declaration is there to allow managed code to implement a COM server that implements an IStream or takes one as an argument. Lots of .NET framework classes do.

Hans Passant
thanks. Well, so everyone needs a different wrapper for every COM Library that uses an IStream? Also, the imported IStream wrapper I get differs wildly from the ComTypes IStream. It doesn't even have the same operations, and how do you implement this one?: void RemoteRead(out byte pv, uint cb, out uint pcbRead);Can you only read one byte at a time?
Grahame Grieve
A wrapper is just a declaration. Sounds to me you found something else then a plain IStream. Maybe a proxy.
Hans Passant