Windows Vista Forums

Expose a .NET interface to COM as an interface

  1. #1


    pierre.k Guest

    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

  2. #2


    Marc Gravell Guest

    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

  3. #3


    pierre.k Guest

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

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

    > 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

  4. #4


    pierre.k Guest

    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

Expose a .NET interface to COM as an interface

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get to install interface Vadados Vista General 3 14 Jun 2009
Interface not supported HanLee Vista General 4 18 Oct 2007
Can I expose the same interface with two different binding without changing code? StanB Indigo 3 19 Jul 2007
Aero Interface David Vista performance & maintenance 2 28 Jun 2007
Alt+Tab interface John Vista file management 3 12 Jun 2006