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
Get
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?
Edit:
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.
dummy : Has the wrapper to be a VB6 user control? Or can I do some magic on the dotNet side?RS Conley : Your choice. The wrapper will pretty much duplicate the original control except make the default property work the way you want. If you want to use a default property with no parameters then you will need to definitely use the vb6 user controldummy : Thank you for your insight. I will accept this answer in a few days, if nobody else answers. -
There is no other way but to create a wrapper in VB6 to mimic the default property behavior of VB6. I have had to create several interop user controls and this was the main reason we had to wrap a .Net interop control again in VB6 (to avoid a lot of code change and huge testing effort).
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.