Platform SDK: TAPI

Receive a Call

The following code snippet demonstrates handling of new call notifications, such as finding or creating appropriate terminals to render the media. This snippet 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 snippet, 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.

Note  This snippet does not have the error checking and releases appropriate for real code.

C++ Code Snippet[C++]

// 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. 

Case TE_CALLNOTIFICATION:
{
    // Get the ITCallNotification interface.
    ITCallNotificationEvent * pNotify;
    pEvent->QueryInterface( 
        IID_ITCallNotificationEvent, 
        (void **)&pNotify 
        );

    // Get the ITCallInfo interface.
    ITCallInfo * pCallInfo;
    pNotify->get_Call( &pCallInfo);
    
    // Get the ITBasicCallControl interface.
    ITBasicCallControl *    pBasicCall;
    pCallInfo->QueryInterface(
        IID_ITBasicCallControl,
        (void**)&pBasicCall
        );

    // Get the ITAddress interface.
    ITAddress * pAddress;
    pCallInfo->get_Address( &pAddress );
    
    // Create the required terminals for this call.
    {
        // See the Select a Terminal code snippet.
    }
    // Complete incoming call processing.
    pBasicCall->Answer();
} 

Visual Basic Code Snippet[Visual Basic]

' 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. 
If TapiEvent = TE_CALLNOTIFICATION Then
    ' Get the ITCallNotification interface.
    Dim objCallNotificationEvent As ITCallNotificationEvent
    Set objCallNotificationEvent = pEvent

   'query ITCallInfo interface for the new call, and store it
    Dim gobjReceivedCallInfo As ITCallInfo
    Set gobjReceivedCallInfo = objCallNotificationEvent.Call

    ' Get the ITBasicCallControl interface.
    Dim objCallControl As ITBasicCallControl
    Set objCallControl = gobjReceivedCallInfo

    ' Create the required terminals for this call.
    ' See the Select a Terminal code snippet.
    
    'Answer
    objCallControl.Answer
End If 

See Also

Events, ITTAPIEventNotification, ITTAPI::RegisterCallNotifications, ITCallNotificationEvent, ITCallInfo, ITBasicCallControl, ITTerminalSupport