Hi all,
I have created vb.net user control that has to be used by vb6 form.
Everything goes well with putting the vb.net user control on the VB6 form
until I want to receive any event from my control. The event handler is
displayed on VB6 IDE combo and you can create a sub for it as usual, but when
I run the vb6 form to test it, it won't work.
I have spent too much time til now with that without finding solution.
Can anybody help me ?
Thanks a lot,
Marek
in**@mmsoftdev. sk
The codes are as follows:
-----------------------------------------------------------
VB.NET user control
-----------------------------------------------------------
Imports System.Runtime. InteropServices
Imports System.Text
Imports Microsoft.Win32
Imports System.Reflecti on
Public Delegate Sub ButtonPressedDe legate()
' Step 1: Defines an event sink interface (ButtonEvents) to be
' implemented by the COM sink.
<GuidAttribute( "1c646f53-ce4e-4bb6-8a67-f94a13172431"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )> _
Public Interface IButtonEvents
Sub ButtonPressed()
End Interface
<Guid("f1bc2b 4d-9844-469d-849c-cfe7f456b989"), _
ComSourceInterf aces("vbNetClar ifyTest.IButton Events, vbNetClarifyTes t")> _
Public Class TestButton
'#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 InterfaceId As String =
"e32ccb34-07c6-4db3-aa0f-1e5b364d513c"
' Public Const EventsId As String = ""
'#End Region
Public Event ButtonPressed As ButtonPressedDe legate
' 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()
Call InitializeCompo nent()
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
RaiseEvent ButtonPressed()
End Sub
<ComRegisterFun ction()> _
Private Shared Sub ComRegister(ByV al t As Type)
Dim keyName As String = "CLSID\" & t.GUID.ToString ("B")
Dim key As RegistryKey = Registry.Classe sRoot.OpenSubKe y(keyName,
True)
key.CreateSubKe y("Control").Cl ose()
Dim subkey As RegistryKey = key.CreateSubKe y("MiscStatus ")
subkey.SetValue ("", "131457")
subkey = key.CreateSubKe y("TypeLib")
Dim libid As Guid = Marshal.GetType LibGuidForAssem bly(t.Assembly)
subkey.SetValue ("", libid.ToString( "B"))
subkey = key.CreateSubKe y("Version")
Dim ver As Version = t.Assembly.GetN ame().Version
Dim version As String = String.Format(" {0}.{1}", ver.Major, ver.Minor)
If version = "0.0" Then version = "1.0"
subkey.SetValue ("", version)
End Sub
' This is called when unregistering
<ComUnregisterF unction()> _
Private Shared Sub ComUnregister(B yVal t As Type)
' Delete entire CLSID\{clsid} subtree
Dim keyName As String = "CLSID\" + t.GUID.ToString ("B")
Registry.Classe sRoot.DeleteSub KeyTree(keyName )
End Sub
End Class
-----------------------------------------------------------
VB6 FORM
-----------------------------------------------------------
Private Sub TestButton1_But tonPressed()
MsgBox "test"
End Sub