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
>
>
|