Default property for dotNet Interop Usercontrol


I need to set the default property of a dotNet Control used by an VB6 Application.

<ComClass(myControl.ClassId, myControl.InterfaceId, myControl.EventsId)> _
<DefaultProperty("NewProperty")> _
Public Class myControl

    Public Const ClassId As String = "86252de2-ca87-4468-adbe-ad7c47747759"
    Public Const InterfaceId As String = "c1cbf1a1-24bb-46c3-88a4-813eb4917845"
    Public Const EventsId As String = "954ed890-011c-4908-ab33-610159fe6eb1"

    Private newPropertyValue As String
    Public Property NewProperty() As String
            Return newPropertyValue
        End Get
        Set(ByVal value As String)
            newPropertyValue = value
        End Set
    End Property
End Class

The DefualtProperty Attribute does not do the trick.

I have read here that manually setting the DispId to Zero should do the trick. But if I do this:

<DispId(0)> Public Property NewProperty() As String

Visual Basic kindly informs me that the DispId Zero is reserved for the DefaultProperty. Yeah. I know that. I want that. But how?


Default Public Property NewProperty(ByVal foo As Integer) As String

Does work as the property now shows up as the default property in VB6. But this will not solve my problem, because there is code which I can't change, which will do something like this:

aStringVariable = myUserControlInstance

This MSDN article has some information about this.

because there is code which I can't change

If that the case then you need to create a wrapper class around the original .NET Class and export that as the control used by VB6. Then you can mark the default property as using the default keyword.