473,769 Members | 6,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unable to receive .NET event in VB6

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


Feb 27 '06 #1
1 3463
Hi all,

as I can see no reply to my question after several day.
Beside waiting for any reply I have searched for solution.
And I found one. It is a dirty solution but works,and actualy it is a Java
style solution.

Solution is as follows:

Create one interface with method you vant to use as event for exmple like
this:

Imports System.Runtime. InteropServices
Imports EventInfoSuppor t

<ComVisible(Tru e)> _
Public Interface ICICCoreEventsL istener
<ComVisible(Tru e)> _
Sub ExtendedObjectE vent(ByVal info As EventInfoObject )
End Interface

Then in your user control that will fire an event add two methods and
declare one variable as ArrayList. Variable will hold an listeners that are
listening for method call and metioned methods are used for adding and
removing listeners from the list of listeners.

Private mlisteners As New ArrayList

<ComVisible(Tru e)> _
Public ReadOnly Property Listeners() As ArrayList
Get
Return mlisteners
End Get
End Property

<ComVisible(Tru e)> _
Public Sub AddEventListene r(ByVal listen As ICICCoreEventsL istener)
If listen Is Nothing Then
Return
End If
If (Not Listeners.Conta ins(listen)) Then
Call Listeners.Add(l isten)
End If
End Sub

<ComVisible(Tru e)> _
Public Sub RemoveEventList ener(ByVal listen As ICICCoreEventsL istener)
If listen Is Nothing Then Return
If (Listeners.Cont ains(listen)) Then
Call Listeners.Remov e(listen)
End If
End Sub

After that on place when you want to fire an event add following:

For Each l As ICICCoreEventsL istener In Listeners
If Not l Is Nothing Then
l.ExtendedObjec tEvent(info)
End If
Next

So this is an VB.NET 2003/5 side. Now here is the VB6 side:

Implements ICICCoreEventsL istener

Private Sub ICICCoreEventsL istener_Extende dObjectEvent(By Val info As
EventInfoSuppor t.EventInfoObje ct)
' do something here after catching of our pseudo event
End Sub

So this is my solution that worked fine also with combination of ClarifyCRM
screen - VB6 control - VB.NET control. There are limitations on CrarifyCRM
side of version 10, that forced me to use VB6 control between Clarify screen
and VB.NET user control.

The class EventInfoSuppor t.EventInfoObje ct is own implementation of
EventInfo class because the VBExtender EventInfo object is not more supported
in .NET and is is not the same as System.Refrecti on.EventInfo object. So I
had to make such own implementation to be compatible with VB6 and VB.NET.

I am not so much satisfied with this forum because of answering speed and MS
itself because of backward compatibility support for events. There is problem
with events also on C# side as well.

Hope it will helps to others too. In case of additional question write me an
email to in**@mmsoftdev. sk.

Bye,

Marek
"Marek Murin" wrote:
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

Mar 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3603
by: wang xiaoyu | last post by:
Hello,everyone. my program runs well in windows,i use tkSimpleDialog to receive some input,but when i copy my program into Linux RH8.0,entrys in my tkSimpleDialog derived Dialog have a vital problem:only one entry can receive key event,'tab' key to navigate between entrys is not valid too,when i use mouse to focus a entry(which can not navigate through 'tag' key),no matter what key i pressed the entry receive no reply.But in window they...
0
9989
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two errors we continue to receive: Source: System Message: The operation has timed-out. Target Function: System.Net.WebResponse GetResponse()
2
10116
by: Craig | last post by:
Hi I listen on a port, when data is received I raise an event (OnMessageReceived) in the while loop as follows: private void WaitForConnection() { TcpListener listener = new TcpListener(IPAddress.Any, 1234); Stream data = null; Socket socket = null;
0
1820
by: Peter O'Reilly | last post by:
I receive the following error when I post a webpage: "Unable to validate error" - System.Web.HTTPException. The web page is an ASP WebForm page. I have a few controls on the page that when selected (e.g. ASP.NET calendar control, HTML radio/option buttons), a postback occurs. In addition, I have a input button, that when clicked, initiates a HTTP Post Request. Notably the input button utilizes client side javascript to change the
0
1313
by: developer | last post by:
I am trying to get a custom provider to receive health monitoring events in vb.net, whidbey beta 1. I have a health monitoring setup like this in my web.config: <healthMonitoring enabled="true"> <providers> <add name="LocalSQL" type="System.Web.Management.SqlWebEventProvider" connectionStringName="connLocalSQL" /> <add name="CustomProvider"
6
17205
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically, process and output to the screen in my application when a message arrived. But the problem is how do I read the SMS message immediately when it arrived without my handphone BeEPINg for new message ? I read up the AT commands, but when getting down...
6
3635
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a list of all of my webs, however if I attempt to open a site under and web other than localhost I receive the message: "Unable to open the Web 'http://localhost/anywebappname'. The Web 'http://localhost/anywebappname' does not exist" Obviously...
1
4032
by: Terrance | last post by:
I'm trying to create a small messenger program that uses the tcpclient and tcplistenter objects. When I start the application and run the thread that fires the tcplistener; once the client sends data then closes the stream and the connection I receive the message Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. How can I keep the connection listener listening for new traffic?...
5
2523
by: xirowei | last post by:
public class Result { private int countA = 0; private int countB = 0; private int statement; private boolean statusA = false; private boolean statusB = false; private int arrayA = new int; <= the problem seem like happen at here? private int arrayB = new int; <= the problem seem like happen at here?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.