PC Review


Reply
Thread Tools Rate Thread

C# x VB6 - EventHandler

 
 
Li
Guest
Posts: n/a
 
      9th Jan 2007
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


 
Reply With Quote
 
 
 
 
Frank Rizzo
Guest
Posts: n/a
 
      9th Jan 2007
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
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To New(EventHandler) or !To New(EventHandler) John Kraft Microsoft C# .NET 8 18th Jun 2008 03:57 PM
need help with EventHandler Sascha Dietl Microsoft C# .NET 4 9th Aug 2006 10:35 AM
Eventhandler Kalim Julia Microsoft VB .NET 2 28th Feb 2006 10:41 AM
RE: Eventhandler Mohamoss Microsoft C# .NET 0 5th Jun 2004 01:32 PM
EventHandler Matias Szulman Microsoft C# .NET 3 15th Oct 2003 12:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:59 PM.