HighTechTalks DotNet Forums  

IStream problem

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss IStream problem in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Andrew Brook
 
Posts: n/a

Default IStream problem - 10-26-2007 , 07:45 AM






Hi everyone,

I'm attempting to rewrite an ATL component in .NET. The only part of the
functionality i'm having problems with is a particular method that needs to
write to a passed IStream.

My calling application is written in using MFC. I've attempted in my new
c#.net component to accept a System.Runtime.InteropServices.ComTypes.IStream
as a parameter, but the MFC application compains saying it can't convert an
IStream to a System.Runtime.InteropServices.ComTypes.IStream. I know it's
got to be more complicated than what i've already tried, but has anyone got
any pointers?

for info I'm using C# .NET 2.0

thanks,
Andrew






Reply With Quote
  #2  
Old   
Andrew Brook
 
Posts: n/a

Default Re: IStream problem - 10-29-2007 , 05:18 AM






Thanks Mattias,

Yes, I am referencing the assembly directly. Since reading your post i've
tried using regasm.exe to register the .net assembly and create a .tlb file.
The dll registered fine, then in my MFC application I added a COM reference
to the dll but I get a message

"Type library 'X' was exported from a CLR assembly and cannot be re-imported
as a CLR assembly."

Given that I was attempting to import the COM types rather than the .NET
reference directly, I don't really understand what the message means.

thanks for your help,
Andrew

"Mattias Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote

Quote:
Andrewm

My calling application is written in using MFC. I've attempted in my new
c#.net component to accept a
System.Runtime.InteropServices.ComTypes.IStream
as a parameter, but the MFC application compains saying it can't convert
an
IStream to a System.Runtime.InteropServices.ComTypes.IStream.

If the C++ code knows that the parameter type is
S.R.IS.ComTypes.IStream you must be compiling with managed code
support and referencing the implementing assembly directly. Don't you
want to just consume the existing COM interface?

Anyway, to turn a native IStream* to the corresponding managed
interface, call Marshal.GetObjectForIUnknown and then cast the result
to ComTypes.IStream.



Mattias

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



Reply With Quote
  #3  
Old   
Andrew Brook
 
Posts: n/a

Default Re: IStream problem - 10-30-2007 , 05:44 AM



I sorted the error I was seeing by not adding a reference to the tlb but by
using the syntax:
#import "libid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

but I think it would also have work if I'd used a private copy of the tlb
and dll in the build directory and then used #import "myDLL.tlb"

this approach seems to suit me much better than directly importing the .NET
assembly as a reference.

I'll respond again once I completely solve my IStream problem

thanks,
Andrew



"Andrew Brook" <ykoorb (AT) hotmail (DOT) com> wrote

Quote:
Thanks Mattias,

Yes, I am referencing the assembly directly. Since reading your post i've
tried using regasm.exe to register the .net assembly and create a .tlb
file. The dll registered fine, then in my MFC application I added a COM
reference to the dll but I get a message

"Type library 'X' was exported from a CLR assembly and cannot be
re-imported as a CLR assembly."

Given that I was attempting to import the COM types rather than the .NET
reference directly, I don't really understand what the message means.

thanks for your help,
Andrew

"Mattias Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote in message
news:O56wLyBGIHA.536 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Andrewm

My calling application is written in using MFC. I've attempted in my new
c#.net component to accept a
System.Runtime.InteropServices.ComTypes.IStream
as a parameter, but the MFC application compains saying it can't convert
an
IStream to a System.Runtime.InteropServices.ComTypes.IStream.

If the C++ code knows that the parameter type is
S.R.IS.ComTypes.IStream you must be compiling with managed code
support and referencing the implementing assembly directly. Don't you
want to just consume the existing COM interface?

Anyway, to turn a native IStream* to the corresponding managed
interface, call Marshal.GetObjectForIUnknown and then cast the result
to ComTypes.IStream.



Mattias

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





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.