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 / New Users / October 2006

Tip: Looking for answers? Try searching our database.

COM Interop issue : .Net is being too 'smart'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob S - 26 Oct 2006 09:57 GMT
I am having trouble with the following scenario....

Assembly A
Returns a managed implementation of COM IStream interface to the
unmanaged world
=============

/////////////////
[ComImport]
[GUID("..")]
interface IStreamAssemblyA
{
..
}

class MyStreamImpl : IStreamAssemblyA
{
.........
}

IntPtr GetStreamImpl()
{
MyStreamImpl obj = new MyStreamImpl();
IntPtr ret =
Marshal.GetComInterfaceForObject(obj,typeof(IStreamAssemblyA));
return ret;
}
///////////////////

Assembly B
Gets and uses a COM IStream interface from the unmanaged world. In
case the implementation is an unmanaged one, everything works OK. In
case the implementation is actually from assembly A above (or any
other managed implementation), the cast fails as shown below.....
==========

/////////////////
[ComImport]
[GUID("..")]
interface IStreamAssemblyB
{
..
}

IntPtr GetStreamFromUnmanagedWorld()
{
..
}

void UseStream()
{
IntPtr streamUnk = GetStreamFromUnmanagedWorld();

object obj = Marshal.GetObjectForIUnknown(streamUnk); // obj is
actually class MyStreamImpl from assembly A above

IStreamAssemblyB stream = obj as IStreamAssemblyB; // this fails
becuase of different ".Net type" of obj and stream
}
/////////////////

The above problem exists becuase .Net does not recognize that even though
IStreamAssemblyA and IStreamAssemblyB are different ".Net types" they are
actually COM interfaces imported into .Net and so the cast above should be
allowed (and QueryInterface should be used internally).

How can I solve this issue? Its not possible to have a common IStream
declartion becuase AssemblyA and AssemblyB are not related in any way except
to the extent that assembly B happens to use the managed IStream
implementation from assembly A.

Any help would be appreciated!

Bob
TDC - 26 Oct 2006 15:50 GMT
Create AssembyC in which you place IStreamAssemblyCommon and then
reference that from both A and B.

> I am having trouble with the following scenario....
>
[quoted text clipped - 70 lines]
>
> Bob
Bob S - 26 Oct 2006 16:07 GMT
As I said, its not possible to have a common IStream becuase assembly A (the
managed implementation) is not under my control. I could be consuming a
managed implementation from any arbitrary 3rd party assembly.

Bob

> Create AssembyC in which you place IStreamAssemblyCommon and then
> reference that from both A and B.
[quoted text clipped - 75 lines]
>>
>> Bob

Rate this thread:







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.