Hi
I'm trying to use a .Net User Control in a VB6 Form.
I've created the control, as a class of a class library, adding references to System.Windows.Form. The class inherits from UserControl and implent an interface that is suposed to expose the control's methods to com:
Class declaration:
<GuidAttribute("8DFE85EE-604A-4350-B4FC-8B6E97CC1A08"), _
ClassInterface(ClassInterfaceType.None)> _
Public Class UserControl1
Inherits System.Windows.Forms.UserControl
Implements IUserControl1
'Constructor and initialize components
public function doSomething() as string
return "hello"
end function
End Class
' Interface
Imports System.Runtime.InteropServices
<InterfaceTypeAttribute(ComInterfaceType.Interface IsIUnknown)> _
Public Interface IEJSimple
function doSomething() as string
End Interface
Then i execute de tlbexp and regasm commands and create a new project in visual basic 6 with reference to the tlb generated with tlbexp.
with this code:
Private Sub Form_Load()
Dim o As Object
Set o = Me.Controls.Add("mySolution.UserControl1", "o")
o.Visible = True
End Sub
I can add the control to the VB6 form i'm not able to call the doSomething() method. The error i get is "the object does not admit that property or method(error #438)"
I also tried to add the control to the
VB form as follow:
Dim o As mySolution.UserControl1
Set o = Me.Controls.Add("mySolution.UserControl1", "o")
But i get a type missmatch error.
¿What is wrong with this o what i'm forgetting?
Thanks