473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# x VB6 - EventHandler

Li
Hello,

I have a C# class library with a form inside (ComVisible(true)) that is
instantiated by a VB6 executable. So far, so good. :-)

I created an event at C# that has to be handled by VB6. This event works
fine when I use a VB.Net executable, but at VB6 it doesn't even recognize
that the C# form has an event.

I will be very grateful if someone could help me, showing my mistakes.

Thanks in advance.

Below is the concise code that works at VB.Net but (a similar code, written
in VB) do not at VB6:

[ComVisible(true)]
public partial class frmMain: Form
{
public event EventHandler OnDoSomething;

public void DoSomething()
{
if (this.OnDoSomething() != null)
this.OnDoSomething(this, new EventHandler());
}
}

---------------------------------------------------

Dim WithEvents frmTest As <library reference>

Public Sub TestOnDoSomething(ByVal sender as Object, ByVal e as EventArgs)
Handles frmTest.OnDoSomething
...
End Sub
Jan 9 '07 #1
1 1763
Li wrote:
Hello,

I have a C# class library with a form inside (ComVisible(true)) that is
instantiated by a VB6 executable. So far, so good. :-)

I created an event at C# that has to be handled by VB6. This event works
fine when I use a VB.Net executable, but at VB6 it doesn't even recognize
that the C# form has an event.

I will be very grateful if someone could help me, showing my mistakes.
As far as I understand, you have to create an interface where you define
your events and then have your class inherit from that interface.

Just as an FYI (and I am no interop expert), I was never able to achieve
stability when firing events from .NET into a VB6 client. I would get
random crashes in the VB6 ide and occasionally when running my VB6 app
as a standalone EXE.

I should point out that my C# code was a multithreaded piece and that
may have contributed to the problems.
>
Thanks in advance.

Below is the concise code that works at VB.Net but (a similar code, written
in VB) do not at VB6:

[ComVisible(true)]
public partial class frmMain: Form
{
public event EventHandler OnDoSomething;

public void DoSomething()
{
if (this.OnDoSomething() != null)
this.OnDoSomething(this, new EventHandler());
}
}

---------------------------------------------------

Dim WithEvents frmTest As <library reference>

Public Sub TestOnDoSomething(ByVal sender as Object, ByVal e as EventArgs)
Handles frmTest.OnDoSomething
...
End Sub

Jan 9 '07 #2

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

Similar topics

2
by: Sandor Heese | last post by:
Question, When using BeginInvoke (on a From to marshal to the UI thread) with the EventHandler delegate I see some strange behaviour. The problem is that I call the UpdateTextBox method with a...
3
by: Remco | last post by:
Hello, Serverside I'm generating a html page. There are different controls for which I want to create an eventhandler manually. Like: document.forms.TextBox1.onchange = EventHandler;...
0
by: dominosly | last post by:
Okay, this is a rather complicated problem, so here is the short of it: I am using a custom designed user control that simply writes out a plain old html submit button to the page. When the...
12
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and...
5
by: JMWilton | last post by:
Is there a way to determine what has been added to the eventhandler list? I have code that uses += and -= to turn event handling code on and off. Apparently, it is possible to add the same event...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
9
by: Christopher Weaver | last post by:
Can anyone tell me how I could iterate through a collection of controls on a form while assigning their event handlers to another identical collection of controls on the same form. So far,...
13
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that...
2
by: mawi | last post by:
Hi there, When removing page children controls created dynamically not in last-to-first order, the close button of the last control looses its event wiring, even though the handler is rewired...
2
cornfed
by: cornfed | last post by:
I've got a class to make Templates for different repeaters in my page. in one of these repeaters a linkbutton is needed. This LinkButton needs an event that is in a .cs file somewhere else in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.