Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

Using UCOMIStream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Puncher - 21 Jan 2005 14:17 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.