私は、VB.Net COMクラスが、VBA経由でインターフェイスにアクセスするときに、親クラスにアクセスできる関数を継承しない状況があります。VB.NetComクラス継承
I.e.私は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
このため任意の解決策は、子クラスのインターフェイスを再定義する必要が別にありますか?
ありがとうございます。
両方のクラスのインターフェイスを定義し、子インターフェイスに基本インターフェイスを実装させるようにしてください。 COMコクラスはほとんどの場合、インターフェイス実装のコレクションです。コンパイラに依存するのではなく、明示的に作成します。 – Comintern