Platform SDK: TAPI

Select an Address

The following code snippet demonstrates use of the TAPI object to examine available telephony resources for an address that can handle a specified set of media type requirements. In this snippet, audio and video are the required media.

Before using this code snippet, you must perform the operations in Initialize TAPI.

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

C++ Code Snippet[C++]

// Use the TAPI object to 
// enumerate available addresses.
gpTapi->EnumerateAddresses( &pIEnumAddress );

// Locate an address that can support the 
// media type the application needs.
while ( S_OK == pEnumAddresses->Next(1, &pAddress, NULL) ) )
{
    // Determine the media support.
    pAddress->QueryInterface(
        IID_ITMediaSupport,
        (void **)&pMediaSupport
        );

    // In this snippet, the required media type is already known.
    // The application can also use the address object to
    // enumerate the media supported, then choose from there.
    pMediaSupport->QueryMediaType(
        TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO,
        &bSupport
        );
    if (bSupport)
    {
        break;
    }
}
// pAddress is now a usable address.

Visual Basic Code Snippet[Visual Basic]

'pick up the collection of Address objects
Dim gobjAddress As ITAddress
Dim objCollAddresses As ITCollection
Set objCollAddresses = gobjTapi.Addresses

'find address that supports the desired type, nSelectedType 
bFound = False
For indexAddr = 1 To objCollAddresses.Count
    Set objCrtAddress = objCollAddresses.Item(indexAddr)
    Set objMediaSupport = objCrtAddress
    Set objAddressCapabilities = objCrtAddress

    If objMediaSupport.QueryMediaType( nSelectedType ) 
        bFound = True
    End If
    
    Set objAddressCapabilities = Nothing
    Set objMediaSupport = Nothing
    Set objCrtAddress = Nothing
    
    If bFound = True Then Exit For
Next indexAddr

Set gobjAddress = objcollAddress.Item(indexAddr)

'If no errors occurred, gobjAddress is now a usable address.

See Also

ITTAPI::EnumerateAddresses, ITMediaSupport, TAPIMEDIATYPE_ Constants