Terminate a Call
The following code example demonstrates how to terminate a call. The operations in the Initialize RTC, Register To Receive Events, and Create a Session and Make a Call code examples must be performed before using this example.
Note This example does not contain error checking or releases appropriate for real code.
C++ Code Example
// // Specify a reason from the RTC_TERMINATE_REASON // enumeration to terminate the call. // hr = pIRTCSession->Terminate(RTCTR_NORMAL); // If (hr != S_OK), process the error here. .... // // This code is placed in the RTCE_SESSION_STATE_CHANGE event handler method. // IRTCSessionStateChangeEvent *pISessionState = NULL; RTC_SESSION_STATE SessionState; // Get the session state interface from the event object. hr = pIDispatch->QueryInterface(IID_IRTCSessionStateChangeEvent, reinterpret_cast<void**> (&pISessionState)); // If (hr != S_OK), process the error here. hr = pISessionState->get_State(&SessionState); // If (hr != S_OK), process the error here. // Handle relevant session states here. switch(SessionState) { ..... // Handle the disconnect notification. case RTCSS_DISCONNECTED: { // The session must be released and set to NULL. pIRTCSession->Release(); pIRTCSession = NULL; break; } .... }
Visual Basic Code Example
'Set the error handling routine here. ' On Error GoTo MyErrorRoutine 'In the method for handling user events, the user 'clicks a button to end the call. Call g_objSession.Terminate(RTCTR_NORMAL) 'In the Session State Change event handler and for the 'RTCSS_DISCONNECTED event, free memory by setting objects to 'Nothing 'Declare the session event interface. Dim objSessionEvent As IRTCSessionStateChangeEvent Dim state As RTC_SESSION_STATE 'pEvent is an "Unknown" object; query it to get 'the IRTCSessionStateChangeEvent interface. Set objSessionEvent = pEvent state = objSessionEvent.state Select Case state .... 'Handle the disconnect notification. Case RTCSS_DISCONNECTED ' Free the Session and Participant objects. Set g_objSession = Nothing Set g_objParticipant = Nothing .... End Select