Search code examples
vb.netcomidispatch

How to create a VB.NET COM-visible interface without IDispatch?


If I create a COM-visible VB.NET interface, such as:

<ComVisible(True)>
Public Interface IMyInterface
    Sub MyMethod()
End Interface

Then the resulting type library will show IMyInterface inheriting IDispatch. Is there a way to inherit just IUnknown, and not IDispatch?


Solution

  • Use the InterfaceTypeAttribute Class like this:

    <ComVisible(True), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Public Interface IMyInterface
        Sub MyMethod()
    End Interface