开发者

Can I make a function COM Only? (Opposite of <Runtime.InteropServices.ComVisible(False)> )

开发者 https://www.devze.com 2023-03-23 18:52 出处:网络
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)> _

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 d开发者_StackOverflow社区eclaration.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消