I am trying to expose a .NET Structure to COM in a DLL.
I would like to do this within an exposed .Net CLass. As coded the structure is not exposed to VB6.
MSDN indicates that Types can be exposed but they must have a constructor with no parameters.
.Net will not allow me to declare "Public Sub New()" within a structure declaration in the class.
So far the only way I can see of doing this is to declare a separate class that has its own GUIDs and gets registered separately.
The example below is what I am trying to do. When referenced in VB6, the ComClass 1 is available, but the type MyType does not show up as a datatype.
Example:
Imports System.Runtime.InteropServices
<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 = "5A563725-8AD6-4E16-ACA8-7EA378A71762"
Public Const InterfaceId As String = "2423222E-2136-4515-8A67-E6E7B303E62C"
Public Const EventsId As String = "1863DD9A-6C50-49F1-8A61-8476C3CDCCFC"
#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 Structure MyType
Public strTypeString As String
End Structure
Private strString As String
Public Property propString() As String
Get
propString = strString
End Get
Set(ByVal Value As String)
strString = Value
End Set
End Property
End Class
I would like to do this within an exposed .Net CLass. As coded the structure is not exposed to VB6.
MSDN indicates that Types can be exposed but they must have a constructor with no parameters.
.Net will not allow me to declare "Public Sub New()" within a structure declaration in the class.
So far the only way I can see of doing this is to declare a separate class that has its own GUIDs and gets registered separately.
The example below is what I am trying to do. When referenced in VB6, the ComClass 1 is available, but the type MyType does not show up as a datatype.
Example:
Imports System.Runtime.InteropServices
<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 = "5A563725-8AD6-4E16-ACA8-7EA378A71762"
Public Const InterfaceId As String = "2423222E-2136-4515-8A67-E6E7B303E62C"
Public Const EventsId As String = "1863DD9A-6C50-49F1-8A61-8476C3CDCCFC"
#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 Structure MyType
Public strTypeString As String
End Structure
Private strString As String
Public Property propString() As String
Get
propString = strString
End Get
Set(ByVal Value As String)
strString = Value
End Set
End Property
End Class