0

我尝试按照 MSDN 上的示例进行操作。我有一个需要从 VB.Net VSTO Excel 工作簿访问的字符串参数。我在 Add-In 中打开了 ComVisible 并声明了我的接口,并声明了一个类来公开该接口。我要公开的函数称为 CheckLicStatus(),它应该根据许可证状态返回一个字符串,“活动”或“过期”。帮助!我也觉得我从传递的对象中检索字符串参数的方式是错误的。

这是公开函数的加载项代码:

   'Open up ComVisible
    <ComVisible(True), InterfaceType(ComInterfaceType.InterfaceIsDual) _
    Public Interface IAddInLicense
        Function CheckLicStatus() As String
    End Interface

    'Decalre class to expose to out of process clients
    <ComVisible(True)> _
<ClassInterface(ClassInterfaceType.None)> _
    Public Class AddInLicense
        Implements IAddInLicense

        ' get license status 
        Public Function CheckLicStatus() As String Implements IAddInLicense.CheckLicStatus
           
            CheckLicStatus = ""
            
                    If LicIsActive Then
                        CheckLicStatus = "Active"
                        MsgBox("license is active")
                    Else
                        CheckLicStatus = "Expired"
                        MsgBox("License is Expired")
                    End If
            
        End Function
    End Class

    Private myLicense As AddInLicense
    Protected Overrides Function RequestComAddInAutomationService() As Object
        If myLicense Is Nothing Then
            myLicense = New AddInLicense()
        End If
        Return myLicense
    End Function

这是试图访问函数值的 VSTO excel 代码:

    Public Sub CheckLicStatus()

        Dim addIn As Office.COMAddIn = Globals.ThisWorkbook.Application.COMAddIns.Item("EstimateAddIn")
        Dim myLicense As EstimateAddIn.IAddInLicense = TryCast( _
            addIn.Object, EstimateAddIn.IAddInLicense)
      
            Try
                licstatus = myLicense.CheckLicStatus()
                MsgBox(licstatus)
            Catch ex As Exception
                MsgBox("Could Not Get licstatus")
            End Try

    End Sub

我在一个单独的模块中也有这段代码:

Namespace EstimateAddIn
    Interface IAddInLicense

        Function CheckLicStatus() As String

    End Interface
End Namespace

4

0 回答 0