CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: COM events

  1. #1
    Guest

    COM events

    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?


  2. #2
    Guest

    Re: COM events

    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



  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: COM events

    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

  4. #4
    Join Date
    Nov 2000
    Posts
    5

    Re: COM events

    How would be done the other way around. How can
    events be handled in VC ? If the com is developed in VB..

    Thanx


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured