Expose a .NET interface to COM as an interface


P

pierre.k

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.
 
Ad

Advertisements

P

pierre.k

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
 
Ad

Advertisements

P

pierre.k

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top