我可以只使用COM功能吗?(与<Runtime.InteropServices.ComVisible(False)>相反)

Mat*_*lko 5 vb.net vb6 com com-interop vb6-migration

我在我的VB.NET DLL中有一些功能,我可以通过使用以下内容从我的VB6应用程序"隐藏":

<Runtime.InteropServices.ComVisible(False)> _
Run Code Online (Sandbox Code Playgroud)

但有没有办法让COM客户端只能看到一个函数,而不是.NET程序集?

这样我可以在.NET端使用共享方法,避免了实例声明的需要.

yms*_*yms 3

您也许能够通过使用显式接口实现来实现您想要的目标。您可以声明一个将由 COM 客户端使用的接口,另一个将用于 .NET 客户端的接口,从而将实现类中的所有方法保留为私有。代码可能如下所示:

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
Run Code Online (Sandbox Code Playgroud)


我不得不说,我不明白你的意思:“这样我就可以在 .NET 端使用共享方法,从而避免需要实例声明。”