I am developing an COM library that uses the IStream
interface to read and write data. My MIDL code looks like this:
interface IParser : IUnknown
{
HRESULT Load([in] IStream* stream, [out, retval] IParsable** pVal);
};
Since IStream
and it's base interface ISequentialStream
are not defined inside a type library, they get defined in mine. So far so good. However, when I view my type library with OLEView, ISequentialStream
only defines the members RemoteRead
and RemoteWrite
, while I expected Read
and Write
, since they are what I am actually calling. Even more strange is, that the the MSDN lists those two members (additionally to the original ones), but states they are not supported.
The question
So what are those members and how do I use them from a client (e.g. a managed application to create a managed Stream
wrapper for IStream
)?
The long story
I want to implement a wrapper on the client side, that forwards IStream
calls to .NET streams, like System.IO.FileStream
. This wrapper could inherit from IStream
like so:
public class Stream : Lib.IStream
{
public System.IO.Stream BaseStream { get; private set; }
public Stream(System.IO.Stream stream)
{
this.BaseStream = stream;
}
// All IStream members in here...
public void Read(byte[] buffer, int bufferSize, IntPtr bytesReadPtr)
{
// further implementation...
this.BaseStream.Read();
}
}
And then, I want to call my server with this wrapper:
var wrapper = new Stream(baseStream);
var parsable = parser.Load(wrapper);
The problem is, that Lib.Stream
in the previous example only provides RemoteRead
and RemoteWrite
, so that server calls to stream->Read()
would end up in no mans land. As far as I understood, there is System.Runtime.InteropServices.ComTypes.IStream
for managed COM servers, but in my example I have a unmanaged COM server and a managed client that should provide IStream
instances.