Answer a Call

The following code example demonstrates how to receive an incoming call. The operations in the Initialize RTC and Register to Receive Events 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

IRTCSessionStateChangeEvent *pISessionState = NULL;

// Create the session state interface.
hr = pIDispatch->QueryInterface( IID_IRTCSessionStateChangeEvent,
                          reinterpret_cast<void**> (&pISessionState));

// If (hr != S_OK), process the error here.

// Get the current session state.
hr = pISessionState->get_State(&SessionState);

// If (hr != S_OK), process the error here.

// Handle all session states.
    // Handle the incoming call.
        // Play a ring on the local computer.
        m_pIRTCClient->PlayRing(RTCRT_PHONE, VARIANT_TRUE)

         hr = pISessionState->get_Session(&pIRTCSession);

         // If (hr != S_OK), process the error here.

         // Answer the incoming session.
         hr = pIRTCSession->Answer();

         // 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 g_objSession As IRTCSession 

'Declare the session event interface.
Dim objSessionEvent As IRTCSessionStateChangeEvent
'pEvent is an "Unknown" object; query it
'to get the IRTCSessionStateChangeEvent interface.
Set objSessionEvent = pEvent
state = objSessionEvent.state
Select Case state

    'Handle the incoming call notifications. 

        'Play a ring on the local PC
        'to alert the user of the incoming call.
        Call g_objRTCClient.PlayRing(RTCRT_PHONE, True)

        'Get the incoming session.
        Set g_objSession = objSessionEvent.Session 

        'Answer the call.
        Call g_objSession.Answer
End Select