Click to See Complete Forum and Search --> : COM events


October 8th, 1999, 09:20 AM
I have a C++ method that returns an IDispatch pointer as a return parameter. If that object is an event source, is there a way for a VB client that calls that method to recognize that object as a source of events and to dynamically tie that object to event procedures so that it can respond to events from the object?

October 8th, 1999, 02:30 PM
I am answering my own post in case anyone else cares. In short, yes VB can do this. Instantiate class module, with an unitialized member of the eventsource object type withEvents. Define the relevant event procedures for it. Define a method to set the member variable. Once it is set dynamically at runtime, events are received from the object. To stop events, set the member variable to nothing. A code sample follows.

Private WithEvents m_EventSource As RETURNEVENTSRCTESTSERVERLib.MyEventSrc

Private Sub m_EventSource_MyEvent(ByVal lEvent As Long)

MsgBox ("Got an event")

End Sub

Public Sub SetEventSrc(evtsrc As Object)

Set m_EventSource = evtsrc

End Sub

Ravi Kiran
October 9th, 1999, 01:23 AM
One more point:
You cannot do this defining a event source with dim/private WITHEVENTS identifier w/o first referencing the dll or tlb for that source. i.e
If you want this line:

private withevents m_EventSource as RETURNEVENTSRCTESTSERVERLib.MyEventSrc



to go thru the compilation before running (Cntrl+F5) the library reference to RETURNEVENTSRCTESTSERVERLib should first be set. and thats when the custom events will be understood by VB.

RK

arunmk
November 24th, 2000, 04:13 AM
How would be done the other way around. How can
events be handled in VC ? If the com is developed in VB..

Thanx