• Welcome to Theos PowerBasic Museum 2017.

Late binding of ActiveX events (how to ??)

Started by Steven Pringels, April 15, 2009, 03:45:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Steven Pringels

Hi,

On the PB forum I created a topic on how to do late bounding of activeX events. Actually it was more of a question from my side. Eventually I found out how to do it using a combridge.dll but Dominic Mitchell now stated that one doesn't need a dll to do this. Any ideas ? It seems Jose's old examples would hold the key to this but I didn't find any old examples.

So if one of you can give me some pointers or examples on how I might achieve this I would be grateful.

Cheers
Steven

José Roca

 
If you use my Windows API Headers, there are two include files, EventSink.inc and EventSinkEx.inc.

EventsSinkEx allows to connect events using the function EVX_Advise:


FUNCTION EVX_Advise (BYVAL pdisp AS IDispatch, BYVAL pEvtObj AS IDispatch, BYREF riid AS GUID, BYREF pdwCookie AS DWORD) AS LONG


You need to pass the dispatch pointer of the OCX, the dispatch pointer of the PB event class that will receive the events and the guid of the events interface.

To disconnect events, you need to pass the dispatch pointer of the OCX, the guid of the events interface and the cookie returned by FUNCTION EVX.


FUNCTION EVX_Unadvise (BYVAL pdisp AS IDispatch, BYREF riid AS GUID, BYVAL dwCookie AS DWORD) AS LONG


If for any reason you can't use PB event's classes, then you can use EventsSink.inc, that will pass the events to a provided callback function, e.g.


' // Connect events
hr = EV_Advise(pObject, $IID_ObjectInterface, _
     CODEPTR(ObjectInterface_EventsCallback), 0, dwCookie)

' // Disconnect events
hr = EV_Unadvise(pObject, $IID_ObjectInterface, dwCookie)

' // Events callback function
' // Parameters in DISPPARAMS are in reversed order.
' // The DispGetParam function can be used to extract values from DISPPARAMS.

FUNCTION ObjectInterface_EventsCallback ( _
   BYVAL pthis AS DWORD _               ' // Pointer to the client's IDispatch
, BYVAL dispidMember AS LONG _         ' // Identifier of the event
, BYREF pdispparams AS DISPPARAMS _    ' // Structure containing an array of arguments
, BYREF pvarResult AS VARIANT _        ' // Pointer to the location where the result is to be stored, or NULL if the caller expects no result
, BYVAL pCustData AS DWORD _           ' // Pointer to user defined data
) AS LONG                              ' // Return value

   FUNCTION = %S_OK

   SELECT CASE AS LONG dispidMember
      CASE &H00000001   ' <-- change me
         ' Unpack parameters from DISPPARAMS
      ...
      ...
      ...
      CASE ELSE
        FUNCTION = %DISP_E_MEMBERNOTFOUND
   END SELECT

END FUNCTION


Hope this helps.

Steven Pringels

Wow Jose !! Thank you very much !! This is the way to go !!

;D