Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Expose a .NET interface to COM as an interface

Reply
 
Old 06-19-2008   #1 (permalink)
pierre.k


 
 

Expose a .NET interface to COM as an interface

Hello,
does anyone know if there is a way to expose a .NET interface to COM
as such? Suppose I have code like this:

[ComVisible(true)]
[Guid("....")]
interface IMyInterface {
void Method1();
void Method2();
}

but that does not expose this interface to COM clients, which is
logical, because there is no named identifier specified (.NET does not
allow me to specify [ProgID("...")] attribute to provide a name for
the interface as it does for classes).

Now, I can easily create a .NET class, make it ComVisible and specify
IMyInterface as the default interface. In this case, I can access this
interface by COM clients. But I want the client to see IMyInterface as
such, and possibly let an external COM class (say written in VB6)
implement it. Can this be done?

Thanks in advance for your help,
pierre_k.

My System SpecsSystem Spec
Old 06-19-2008   #2 (permalink)
Marc Gravell


 
 

Re: Expose a .NET interface to COM as an interface

Well, that should work - have you tried making the interface public? (it
is implicitly "internal" in the code posted)

See here:
http://msdn.microsoft.com/en-us/library/46f8ac6z.aspx

Marc
My System SpecsSystem Spec
Old 06-19-2008   #3 (permalink)
pierre.k


 
 

Re: Expose a .NET interface to COM as an interface

On Jun 19, 12:13 pm, Marc Gravell <marc.grav...@xxxxxx> wrote:
Quote:

> Well, that should work - have you tried making the interface public? (it
> is implicitly "internal" in the code posted)
>
> See here:http://msdn.microsoft.com/en-us/library/46f8ac6z.aspx
>
> Marc
Yes, I have tried to make it public, but I accidentaly left out that
part from the code.
Actually, I can see my interface in the exported typelibrary (.tlb
file opened with OleView), but it's not visible from VB6 (using the
Object Browser). I have also tried marking the interface with
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> and
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>, but that does
not make any difference. Any suggestions on what I'm doing wrong?

Thanks,
pierre_k
My System SpecsSystem Spec
Old 06-19-2008   #4 (permalink)
pierre.k


 
 

Re: Expose a .NET interface to COM as an interface

Well, after few hours of fiddling around I found out what the issue
here is. Apparently, when you define a NET interface along with a
ComVisible class with your interface set as the default one (using
ComDefaultInterface attribute), VB6 hides this default interface
entirely from you. Then, when you want to work with that interface in
VB6, you use the name of that implementing class instead.

In any case thank for help, it definitely made me look in the right
direction.
pierre_k
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Interface questions Vista General
Aero Interface Vista performance & maintenance
Aero Interface Vista General
Alt+Tab interface Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46