Register to Receive Events
The following code examples demonstrate how to register to receive events and listen for incoming calls. The operations in the Initialize RTC code example must be performed before using these examples.
Note This example does not contain error checking or releases appropriate for real code.
C++ Code Examples
// // Example 1: Set the event filter. // HRESULT hr = S_OK; long lEventMask; // Set the event mask to receive all event types. lEventMask = RTCEF_ALL; hr = pIRTCClient->put_EventFilter(lEventMask); // If (hr != S_OK), process the error here. // // Example 2: Register the event interface. // // Note: This method is in the CRTCOutgoing class, which // implements the IRTCEventNotification interface. HRESULT hr = S_OK; DWORD dwEventCookie; IUnknown *pUnknown = NULL; IConnectionPointContainer *pCPC = NULL; IConnectionPoint *pCP = NULL; hr = QueryInterface( IID_IUnknown, reinterpret_cast<void**> (&pUnknown) ); // If (hr != S_OK), process the error here. // Get the connection point container interface pointer. hr = pIRTCClient->QueryInterface( IID_IConnectionPointContainer, reinterpret_cast<void**> (&pCPC) ); // If (hr != S_OK), process the error here. // Get the RTC event notification interface // from the connection point container. hr = pCPC->FindConnectionPoint( IID_IRTCEventNotification, &pCP ); // If (hr != S_OK), process the error here. // Call the Advise method to give RTC the IUnknown pointer // for the event. hr = pCP->Advise( pUnknown, &dwEventCookie ); // If (hr != S_OK), process the error here. pCP->Release(); pCPC->Release(); pUnknown->Release(); return hr; // // Example 3: Listen for calls. // // Listen on dynamic and well-known static ports. hr = pIRTCClient->put_ListenForIncomingSessions( RTCLM_BOTH ); // If (hr != S_OK), process the error here.
Visual Basic Code Example
'Set the error handling routine here. ' On Error GoTo MyErrorRoutine 'Usually declared globally Private WithEvents g_objRTCClientWithEvents As RTCClient 'Set the EventFilter to accept all events. 'You can choose to select some or all event filters here. g_objRTCClient.EventFilter = RTCEF_CLIENT Or _ RTCEF_REGISTRATION_STATE_CHANGE Or _ RTCEF_SESSION_STATE_CHANGE Or _ RTCEF_SESSION_OPERATION_COMPLETE Or _ RTCEF_PARTICIPANT_STATE_CHANGE Or _ RTCEF_MEDIA Or _ RTCEF_INTENSITY Or _ RTCEF_MESSAGING Or _ RTCEF_BUDDY Or _ RTCEF_WATCHER ' Register the outgoing interface that will receive the events. Set g_objRTCClientWithEvents = g_objRTCClient ' Listen for incoming calls on dynamic and well-known static ports. g_objRTCClient.ListenForIncomingSessions = RTCLM_BOTH