Imports System.Runtime.InteropServices Imports Microsoft.Office.Interop <ComVisible(True)> _ <Guid("A9FC804C-0EE6-4347-870D-F7CFCD7006D1")> _ Public Interface CustomWorkBook Inherits Excel.Workbook <ComVisible(True)> _ <DispId(&H1000001)> _ Sub ConsoleWriteCount() End Interface <ComVisible(True)> _ <Guid("81C96C5B-A24F-41FD-A4BF-2E65B38C67FB")> _ _ <ClassInterface(ClassInterfaceType.None)> _ Public Class CustomWorkBookClass Inherits Excel.WorkbookClass Implements CustomWorkBook Public Sub New() MyBase.New() End Sub Public Sub ConsoleWriteCount() Implements CustomWorkBook.ConsoleWriteCount Console.WriteLine("Mon classeur contient {0} feuilles", Me.Worksheets.Count) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Interface IVWConnexion Sub X() Sub Y() End Interface Public Class VWConnexion Implements IVWConnexion Public Sub X() Implement IVWConnexion.X ... End Sub Public Sub Y() Implement IVWConnexion.Y ... End Sub End Class
L'héritage, c'est pas encore au point dans le VB.NET
Juste pour être sur, votre classe "enfant" n'ajoute aucune méthode ou propriété à votre classe "parent" ?
Si je comprends bien, vous voulez juste que les deux classes aient les mêmes méthodes, mais qu'une soit COM visible. Ou suis-je à coté de la plaque ?
Public Interface IVWConnexion
Sub X()
Sub Y()
End Interface
Public Class VWConnexion
Implements IVWConnexion
Public Sub X() Implement IVWConnexion.X
...
End Sub
Public Sub Y() Implement IVWConnexion.Y
...
End Sub
End Class
Ne confondez pas héritage et Interoperabilité.
Si votre classe de base n'est pas visible par COM, elle ne peut pas le devenir avec un simple héritage. Ce n'est pas le but de l'héritage.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _ Public Class ComClass1 #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "e8663719-7f31-409f-9a68-7721d9386810" Public Const InterfaceId As String = "4080b332-d374-49a5-87b3-0b84b55026be" Public Const EventsId As String = "06c8c3f5-84fa-4715-97c1-73d40d6dfdd5" #End Region ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub Public Function toto() As String Return "toto" End Function End Class
ComClass(ComClass2.ClassId, ComClass2.InterfaceId, ComClass2.EventsId)> _ Public Class ComClass2 Inherits ComClass1 #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "02c536f1-badf-4a12-8f89-34e509041b1d" Public Const InterfaceId As String = "960cc08f-c520-4b13-ab11-81222ac81973" Public Const EventsId As String = "d26cb9aa-c428-40ec-91a5-1b7b31e5aec8" #End Region ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub End Class
J'ai tenté de rendre visible par COM ma classe parent et sa ne fonctionnais pas mieux
Imports System.Runtime.InteropServices <ComVisible(True)> _ <Guid("A9FC804C-0EE6-4347-870D-F7CFCD7006D1")> _ Public Interface IVWConnexion <ComVisible(True)> _ <DispId(&H1000001)> _ Sub MaSub() <ComVisible(True)> _ <DispId(&H1000001)> _ Function MaFonction() as Integer End Interface <ComVisible(True)> _ <Guid("81C96C5B-A24F-41FD-A4BF-2E65B38C67FB")> _ _ <ClassInterface(ClassInterfaceType.None)> _ Public Class VWConnexion Implements IVWConnexion Public Sub New() ... End Sub Public Sub MaSub() Implements IVWConnexion.MaSub ... End Sub Public Function MaFonction() as Integer Implements IVWConnexion.MaFonction Return 3 End Sub End Class
qu'est-ce que j'ai foutu
''' <summary> ''' Informe qu'une erreur à été rencontré durant l'écriture asyncrone ''' </summary> ''' L’exception rencontrer ''' La requête qui à provoquer l’exception ''' <remarks></remarks> Public Event AsyncErreur(ByVal Ex As Exception, ByVal RequeteEnErreur As String)
<ComClass(VWConnexionCom.ClassId, VWConnexionCom.InterfaceId, VWConnexionCom.EventsId)> _ Public Class VWConnexionCom Inherits VWConnexion #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "625a8a87-c87a-43f3-aef5-6b945d71318f" Public Const InterfaceId As String = "1eb34dbf-040d-4309-a444-66b94aba4597" Public Const EventsId As String = "3562c969-1da2-4e7c-b715-a1ecaf0c966b" #End Region #Region "Redéfinition(s)" Public Shadows Event AsyncErreur(ByVal Ex As Object, ByVal RequeteEnErreur As String) Private Sub VWConnexionCom_AsyncErreur(ByVal Ex As Exception, ByVal RequeteEnErreur As String) Handles MyBase.AsyncErreur RaiseEvent AsyncErreur(Ex, RequeteEnErreur) End Sub #End Region ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub End Class
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _ Public Class ComClass1 #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "e8663719-7f31-409f-9a68-7721d9386810" Public Const InterfaceId As String = "4080b332-d374-49a5-87b3-0b84b55026be" Public Const EventsId As String = "06c8c3f5-84fa-4715-97c1-73d40d6dfdd5" #End Region Public Function toto() As String Return "toto" End Function End Class
<ComClass(ComClass2.ClassId, ComClass2.InterfaceId, ComClass2.EventsId)> _ Public Class ComClass2 Inherits ComClass1 #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId As String = "02c536f1-badf-4a12-8f89-34e509041b1d" Public Const InterfaceId As String = "960cc08f-c520-4b13-ab11-81222ac81973" Public Const EventsId As String = "d26cb9aa-c428-40ec-91a5-1b7b31e5aec8" #End Region ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub Public Function toto2() As String Return "toto2" End Function End Class
<ComClass(ComClass2.ClassId2, ComClass2.InterfaceId2, ComClass2.EventsId2)> _ Public Class ComClass2 Inherits ComClass1 #Region "COM GUIDs" ' These GUIDs provide the COM identity for this class ' and its COM interfaces. If you change them, existing ' clients will no longer be able to access the class. Public Const ClassId2 As String = "02c536f1-badf-4a12-8f89-34e509041b1d" Public Const InterfaceId2 As String = "960cc08f-c520-4b13-ab11-81222ac81973" Public Const EventsId2 As String = "d26cb9aa-c428-40ec-91a5-1b7b31e5aec8" #End Region ' A creatable COM class must have a Public Sub New() ' with no parameters, otherwise, the class will not be ' registered in the COM registry and cannot be created ' via CreateObject. Public Sub New() MyBase.New() End Sub Public Function toto2() As String Return "toto2" End Function End Class