Events in C# generated by VB DLL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have VB6 DLL that contains a Time class. In the time class a timer event is
defined.

The event is declared as:
Public Event Timer(ByVal sKey As String)

And is called with:
RaiseEvent Timer("somestring")

When I instantiate the Time class in my C# application, the Timer event
shows up as an event inside the class. My question is how do I connect/handle
this event in my C# application.

Any help would be greatly appreciated!
 
Jake Haddock said:
I have VB6 DLL that contains a Time class. In the time class a timer event
is
defined.

The event is declared as:
Public Event Timer(ByVal sKey As String)

And is called with:
RaiseEvent Timer("somestring")

When I instantiate the Time class in my C# application, the Timer event
shows up as an event inside the class. My question is how do I
connect/handle
this event in my C# application.

If your instance is called _time, then:

_time.Timer += new EventHandler(_time_EventHandler);

Now, EventHandler is the wrong delegate type. You'd have to see what
delegate type got created to match the signature of your VB6 event, and use
the right one.

John Saunders
 
Understood. Does anyone know how to find the delagate type created for the
VB6 event?

The test delegate I'm now declaring in C#:
public delegate void TimerEventHandler(string sKey);

and then I do the following:
cTmr.Timer += new TimerEventHandler(cTmr_Timer);

When I compile I get the following error:
Cannot implicitly convert type 'myC#.TimerEventHandler' to
'VB6.TimerEventHandler'
 
Jake Haddock said:
Understood. Does anyone know how to find the delagate type created for the
VB6 event?

The test delegate I'm now declaring in C#:
public delegate void TimerEventHandler(string sKey);

and then I do the following:
cTmr.Timer += new TimerEventHandler(cTmr_Timer);

When I compile I get the following error:
Cannot implicitly convert type 'myC#.TimerEventHandler' to
'VB6.TimerEventHandler'

This is saying that the correct delegate type is VB6.TimerEventHandler.

John Saunders
 
Back
Top