[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Andrew Brook

10/26/2007 11:45:00 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





3 Answers

(Mattias Sjögren)

10/26/2007 10:06:00 PM

0

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.n... | http://www.dotneti...
Please reply only to the newsgroup.

Andrew Brook

10/29/2007 9:18:00 AM

0

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@mvps.org> wrote in message
news:O56wLyBGIHA.536@TK2MSFTNGP06.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.n... | http://www.dotneti...
> Please reply only to the newsgroup.


Andrew Brook

10/30/2007 9:45:00 AM

0

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@hotmail.com> wrote in message
news:OyVdGygGIHA.1188@TK2MSFTNGP04.phx.gbl...
> 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@mvps.org> wrote in message
> news:O56wLyBGIHA.536@TK2MSFTNGP06.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.n... | http://www.dotneti...
>> Please reply only to the newsgroup.
>
>