I need to be able to pass streams across the Interop boundary. Using the
article http://support.microsoft.com/default.aspx?scid=kb;en-us;321695 I can
call into and ATL COM object that has a method
STDMETHODIMP CSimpleObj::GetUnmanagedData(IStream** ppData)
from .NET using the following C#
UnmanagedFuncs.IStream stream;
UnmanagedFuncs.ISimpleObj obj = new UnmanagedFuncs.CSimpleObjClass();
obj.GetUnmanagedData( out stream );
UCOMIStream uStream = stream as UCOMIStream;
ComStream ComStream = new ComStream( uStream );
and I now have my IStream data as a UCOMIStream in a Stream derived .NET
class.
However I'm having problems going the other way, ie passing stream data into
COM. If my method is
STDMETHODIMP CSimpleObj::SetUnmanagedData(IStream* pData)
and my C# is
System.IO.MemoryStream mStream2 = new System.IO.MemoryStream();
System.IO.BinaryWriter bw = new System.IO.BinaryWriter( mStream2 );
bw.Write( "Hello!" );
ManagedIStream miStream2 = new ManagedIStream( mStream2 );
UCOMIStream uStream2 = miStream2 as UCOMIStream;
obj.SetUnmanagedData( uStream2 );
then it won't compile, with the error cannot convert from
'System.Runtime.InteropServices.UCOMIStream' to 'UnmanagedHelpers.IStream'.
How can I convince the compiler that my UnmanagedFuncs.IStream is really
just a bog standard IStream?
Cheers,
Chris
Mattias Sj?gren - 21 Jan 2005 19:23 GMT
Chris,
>How can I convince the compiler that my UnmanagedFuncs.IStream is really
>just a bog standard IStream?
You can't. So you have to pick one type, either UnmanagedFuncs.IStream
or UCOMIStream and use that in all your code. You vcan for example
change the ManagedIStream class to implement UnmanagedFuncs.IStream
rather than UCOMIStream.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.