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 / February 2006

Tip: Looking for answers? Try searching our database.

Casting of IStream to UCOMIStream fails

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PRASENJIT BURMAN - 21 Feb 2006 09:24 GMT
I have an application where I need to pass the  data in a COLEStreamFile
object to a method of a .Net class which accepts Stream*. I had implemented
the solution specified in the following article in my application
http://support.microsoft.com/default.aspx?scid=kb;en-us;321340
But it doesn't compile and gives the following error
C2682: cannot use __try_cast to convert from 'LPSTREAM' to
'System::Runtime::InteropServices::UCOMIStream __gc *'

I can see only one difference in the actual implementation in the article
and in my application i.e I have not included any interop assembly. This may
not be the reason for the compilation error. Anyway I cannot figure out
which .dll or .tlb should be used to generate the interop assembly.

Any help will be appreciated.
Prasen
Mattias Sjögren - 21 Feb 2006 22:39 GMT
>But it doesn't compile and gives the following error
>C2682: cannot use __try_cast to convert from 'LPSTREAM' to
>'System::Runtime::InteropServices::UCOMIStream __gc *'

Instead of using __try_cast directly, try calling
Marshal::GetObjectForIUnknown, pass in the LPSTREAM (cast to an
IntPtr) and cast the resulting RCW object to UCOMIStream.

Mattias

Signature

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

PRASENJIT BURMAN - 22 Feb 2006 06:35 GMT
Thanks it worked.
I had another doubt since GetObjectForIUnknown calls AddRef on the COM
interface pointer Do I need to call Release on the underlying interface
pointer before calling on ReleaseCOMObject() on the RCW object. Since
references of the RCW to the COM object is maintained by the runtime while
that of the COM interface is maintained seperately.  

Prasen
Mattias Sjögren - 22 Feb 2006 18:53 GMT
>Do I need to call Release on the underlying interface
>pointer before calling on ReleaseCOMObject() on the RCW object.

No you don't, it will be taken care of when you call ReleaseComObject
or when the RCW is finalized.

Mattias

Signature

Mattias Sjögren [C# 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.