views:

83

answers:

1

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

We managed to expose ENUM but we can't find a way to expose string const.

We 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 on the OLE object viewer, we only see the method. See ScreenShot: screenshot of OLE viewer

Anyone have an idea ?

Thanks,

+2  A: 

If you've got a problems just with the constants , you could always just declare a read-only getter to return each of the constants.

Edit: Added some information that might be relevant below

Quote from the link below:

Visual Basic doesn’t provide a mechanism for adding such values to your type library as public constants, but you can get a similar effect using a global object with read-only properties.

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

This quote is about VB6 though, but it might be the same issue and might give you some more info in there at least.

ho1
We thought of that too, only problem is that we want to "show" the value of the constant to the other side.
JulienC
Not exactly sure what you mean with the word "show" since if you return the value in a getter, the other side could see it? Added a link I stumbled upon that might be of use even though it's for VB6.
ho1
+1 I think it may be a COM limitation - no public string constants. Anyone out there know?
MarkJ
I have some memory that you might be able to declare string constants (char[] or wchar[]) in C++, but too long ago.
ho1
Indeed, we remember of some C++ code with string constant (but can't find the reference anymore). So in conclusion, it must be a .NET -> COM limitation.
JulienC