G
Guest
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
(e-mail address removed)
The codes are as follows:
-----------------------------------------------------------
VB.NET user control
-----------------------------------------------------------
Imports System.Runtime.InteropServices
Imports System.Text
Imports Microsoft.Win32
Imports System.Reflection
Public Delegate Sub ButtonPressedDelegate()
' Step 1: Defines an event sink interface (ButtonEvents) to be
' implemented by the COM sink.
<GuidAttribute("1c646f53-ce4e-4bb6-8a67-f94a13172431"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface IButtonEvents
Sub ButtonPressed()
End Interface
<Guid("f1bc2b4d-9844-469d-849c-cfe7f456b989"), _
ComSourceInterfaces("vbNetClarifyTest.IButtonEvents, vbNetClarifyTest")> _
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 ButtonPressedDelegate
' 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 InitializeComponent()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent ButtonPressed()
End Sub
<ComRegisterFunction()> _
Private Shared Sub ComRegister(ByVal t As Type)
Dim keyName As String = "CLSID\" & t.GUID.ToString("B")
Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(keyName,
True)
key.CreateSubKey("Control").Close()
Dim subkey As RegistryKey = key.CreateSubKey("MiscStatus")
subkey.SetValue("", "131457")
subkey = key.CreateSubKey("TypeLib")
Dim libid As Guid = Marshal.GetTypeLibGuidForAssembly(t.Assembly)
subkey.SetValue("", libid.ToString("B"))
subkey = key.CreateSubKey("Version")
Dim ver As Version = t.Assembly.GetName().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
<ComUnregisterFunction()> _
Private Shared Sub ComUnregister(ByVal t As Type)
' Delete entire CLSID\{clsid} subtree
Dim keyName As String = "CLSID\" + t.GUID.ToString("B")
Registry.ClassesRoot.DeleteSubKeyTree(keyName)
End Sub
End Class
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
(e-mail address removed)
The codes are as follows:
-----------------------------------------------------------
VB.NET user control
-----------------------------------------------------------
Imports System.Runtime.InteropServices
Imports System.Text
Imports Microsoft.Win32
Imports System.Reflection
Public Delegate Sub ButtonPressedDelegate()
' Step 1: Defines an event sink interface (ButtonEvents) to be
' implemented by the COM sink.
<GuidAttribute("1c646f53-ce4e-4bb6-8a67-f94a13172431"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface IButtonEvents
Sub ButtonPressed()
End Interface
<Guid("f1bc2b4d-9844-469d-849c-cfe7f456b989"), _
ComSourceInterfaces("vbNetClarifyTest.IButtonEvents, vbNetClarifyTest")> _
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 ButtonPressedDelegate
' 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 InitializeComponent()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent ButtonPressed()
End Sub
<ComRegisterFunction()> _
Private Shared Sub ComRegister(ByVal t As Type)
Dim keyName As String = "CLSID\" & t.GUID.ToString("B")
Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(keyName,
True)
key.CreateSubKey("Control").Close()
Dim subkey As RegistryKey = key.CreateSubKey("MiscStatus")
subkey.SetValue("", "131457")
subkey = key.CreateSubKey("TypeLib")
Dim libid As Guid = Marshal.GetTypeLibGuidForAssembly(t.Assembly)
subkey.SetValue("", libid.ToString("B"))
subkey = key.CreateSubKey("Version")
Dim ver As Version = t.Assembly.GetName().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
<ComUnregisterFunction()> _
Private Shared Sub ComUnregister(ByVal t As Type)
' Delete entire CLSID\{clsid} subtree
Dim keyName As String = "CLSID\" + t.GUID.ToString("B")
Registry.ClassesRoot.DeleteSubKeyTree(keyName)
End Sub
End Class