Receive a Call

The following code example demonstrates handling of new call notifications, such as finding or creating appropriate terminals to render the media. This example is a portion of the switch statement an application must implement for event handling. The code itself may be contained in the implementation of ITTAPIEventNotification::Event, or the Event method may post a message to a worker thread that contains the switch.

Before using this code example, you must perform the operations in Initialize TAPI, Select an Address, and Register Events.

Also, you must perform the operations illustrated in Select a Terminal following the retrieval of the ITBasicCallControl and ITAddress interface pointers.


This example does not have the error checking and releases appropriate for production code.


// pEvent is an IDispatch pointer for the ITCallNotificationEvent interface of the
// call object created by TAPI, and is passed into the event handler by TAPI. 

    // Get the ITCallNotification interface.
    ITCallNotificationEvent * pNotify;
    hr = pEvent->QueryInterface( 
            (void **)&pNotify 
    // If ( hr != S_OK ) process the error here. 
    // Get the ITCallInfo interface.
    ITCallInfo * pCallInfo;
    hr = pNotify->get_Call( &pCallInfo);
    // If ( hr != S_OK ) process the error here. 

    // Get the ITBasicCallControl interface.
    ITBasicCallControl * pBasicCall;
    hr = pCallInfo->QueryInterface(
    // If ( hr != S_OK ) process the error here. 

    // Get the ITAddress interface.
    ITAddress * pAddress;
    hr = pCallInfo->get_Address( &pAddress );
    // If ( hr != S_OK ) process the error here. 

    // Create the required terminals for this call.
        // See the Select a Terminal code example.
    // Complete incoming call processing.
    hr = pBasicCall->Answer();
    // If ( hr != S_OK ) process the error here.