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 / October 2003

Tip: Looking for answers? Try searching our database.

interop with COM object with mutiple interfaces ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lawrence Lourduraj - 08 Oct 2003 18:09 GMT
I am trying to use a COM object that implements interfaces A, B, C. A is the
default interface for the coclass in the IDL. The COM object is represented
by managed type X.

this is what I am doing in VB.NET,

Dim foo as object = new X()

Dim obj1 as object = foo.GetObj1 // this actually returns a COM object that
implements interface B

obj1.someMethod() // instead of invoking the method on interface B it uses A
and throws a MissingMemberException

Any ideas on how to force .NET to use interface B instead of the default
interface A ? Everything is via automation and "someMethod" in not in the
typelib

Thanks
Mattias Sj?gren - 08 Oct 2003 23:36 GMT
Lawrence,

>Dim obj1 as object = foo.GetObj1 // this actually returns a COM object that
>implements interface B

So why don't you type the variable As B?

Dim obj1 As B = foo.GetObj1

or, if necessary

Dim obj1 As B = CType(foo.GetObj1, B)

Mattias

Signature

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

Lawrence Lourduraj - 10 Oct 2003 15:24 GMT
Hello Mattias:

The COM object (coclass) implements A, B, C all of which are derived from
IDispatch and A is the default.

I did try,

Dim obj1 as B = foo.GetObj1 and

Dim obj1 as B  = CType(foo.GetObj1, B)

and got the same MissingMemberException. Now the returned object (obj1)
actually implements A, B, C but I want "someMethod" to be invoked via B not
A which is the default. This is because the COM component differentiates
between whose IDispatch is used and does different things. I did not write
it so I can explain this design decision !

The IDL contains only one coclass, so "foo" and "obj1" are instances of the
same class. The difference is "GetObj1()" returns a ptr to B after
performing the appropriate cast.

Further NONE of the methods (GetObj1(), someMethod()) are described in the
typelib.

I finally got the following to work,

GetType(B).InvokeMember("someMethod", ..., obj1,...)

I would appreciate it if you could explain why your suggested approach did
not work. I would prefer to use that as it is more intuitive.

Thanks

Lawrence

> Lawrence,
>
[quoted text clipped - 10 lines]
>
> Mattias

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.