How can we provide an open public const for COM interoperability

For historical reasons, we need to set string constants in .NET through the COM interface.

We managed to set ENUM, but we cannot find a way to print the string const.

We will try the following code:

<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 = "608c6545-977e-4260-a3cf-11545c82906a"
    Public Const InterfaceId As String = "12b8a6c7-e7f6-4022-becd-2efd8b3a756e"
    Public Const EventsId As String = "05a2856f-d877-4673-8ea8-20f5a9f268d5"
#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 Const chaine As String = "TEST"

    Public Sub Method()

    End Sub

End Class

But when we look at the OLE object viewer, we only see the method.

Does anyone have an idea?

Thank,

+3
source share
1 answer

If you have problems with only constants, you can always simply declare Get-only getter to return each of the constants.

Edit: Added some information that may be relevant below.

Quote from the link below:

Visual Basic , , .

http://msdn.microsoft.com/en-us/library/aa716309%28VS.60%29.aspx

VB6, , , , , , .

+2

Source: https://habr.com/ru/post/1745947/


All Articles