我有一个情况,即当通过VBA访问接口时,VB.Net COM类未继承可访问父类的函数。
也就是说,我有一个VB.Net COM类(myParent)和一个VB.Net COM子类(myChild)。
我已经搜索并在这里找到了类似的内容:Exposing inherited members of a COM vb.net class,但“尝试这个”解决方案似乎不存在?
以下代码(在VBA中执行时)会失败:
除了需要在子类中重新定义接口之外,是否有其他解决方案?
非常感谢。
也就是说,我有一个VB.Net COM类(myParent)和一个VB.Net COM子类(myChild)。
我已经搜索并在这里找到了类似的内容:Exposing inherited members of a COM vb.net class,但“尝试这个”解决方案似乎不存在?
<ComClass(MyParent.ClassId, MyParent.InterfaceId, MyParent.EventsId)>
Public Class MyParent
#Region "COM GUIDs"
Public Const ClassId As String = "386e628c-872b-41ee-abb2-d2a5dfb4e51e"
Public Const InterfaceId As String = "f4b194f1-9dc9-4f37-93d8-57cb97e05593"
Public Const EventsId As String = "4320826d-a02c-4360-b8b5-4c98569c2b2e"
#End Region
Public Sub New()
MyBase.New()
End Sub
Public Function parent_hello_world() As Boolean
MsgBox("Hello from Parent")
Return True
End Function
End Class
<ComClass(MyChild.ClassId, MyChild.InterfaceId, MyChild.EventsId)>
Public Class MyChild
Inherits MyParent
#Region "COM GUIDs"
Public Const ClassId As String = "65674d29-7bb7-447e-8282-47b9873cec4a"
Public Const InterfaceId As String = "cbcdfb17-c8b9-42e2-bed7-b516b9df6111"
Public Const EventsId As String = "22a8959c-7594-4584-b53d-a087246be623"
#End Region
Public Sub New()
MyBase.New()
End Sub
Public Function child_hello_world() As Boolean
MsgBox("Hello from Child")
Return True
End Function
End Class
以下代码(在VBA中执行时)会失败:
Sub test_me()
Dim tip As New TestInheritance.MyParent
Dim tic As New TestInheritance.MyChild
tip.parent_hello_world() 'this works - directly from parent
tic.child_hello_world() 'this works - child function
tic.parent_hello_world() 'throws an error - not accessible?
End Sub
除了需要在子类中重新定义接口之外,是否有其他解决方案?
非常感谢。