5

I have some functions in my VB.NET DLL which I can 'hide' from my VB6 app by using the following:

<Runtime.InteropServices.ComVisible(False)> _

But is there a way to make a function ONLY visible to COM clients and not to .NET assemblies?

This way I can use Shared methods for the .NET side avoiding the need for an instance declaration.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

1 Answers1

3

You might be able to achieve what you want by using Explicit Interface Implementation. You can declare an interface that will be used by COM clients and another one for .NET clients, leaving all methods private in your implementation class. The code may look like this:

Imports System.Runtime.InteropServices

    Public Interface ITestInterface

    <ComVisible(True)> _
        Sub MyTestMethod()    
    End Interface

    <ComVisible(True)> _
    Public Class TestClass
        Implements ITestInterface

        Private Sub MyTestMethod() Implements ITestInterface.MyTestMethod
        End Sub
    End Class


I have to say that I do not understand what you mean with: "This way I can use Shared methods for the .NET side avoiding the need for an instance declaration. "

Community
  • 1
  • 1
yms
  • 10,361
  • 3
  • 38
  • 68
  • I have loads of little helper methods that should (and would normally) be declared as Shared methods but if I do this then they are not exposed to COM so I want identical methods wrappers calling the same helper method with one wrapper exposed only to COM (Public Sub) and one method exposed only to .NET (Public Shared Sub) I can't get away from the instance declaration on the COM side but I can on the .NET side. – Matt Wilko Aug 02 '11 at 08:09