选择地址
下面的代码示例演示如何使用 TAPI 对象来检查可处理一组指定媒体类型要求的地址的可用电话资源。 在此示例中,音频和视频是必需的媒体。
在使用此代码示例之前,必须在 初始化 TAPI 中执行操作。
注意
此示例没有适用于生产代码的错误检查和发布。
// Declare the interfaces used to select an address.
IEnumAddress * pIEnumAddress;
ITAddress * pAddress;
ITMediaSupport * pMediaSupport;
// Use the TAPI object to enumerate available addresses.
hr = gpTapi->EnumerateAddresses( &pIEnumAddress );
// If (hr != S_OK) process the error here.
// Locate an address that can support the media type the application needs.
while ( S_OK == pIEnumAddress->Next(1, &pAddress, NULL) )
{
// Determine the media support.
hr = pAddress->QueryInterface(
IID_ITMediaSupport,
(void **)&pMediaSupport
);
// If (hr != S_OK) process the error here.
// In this example, the required media type is already known.
// The application can also use the address object to
// enumerate the media supported, then choose from there.
hr = pMediaSupport->QueryMediaType(
TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO,
&bSupport
);
// If (hr != S_OK) process the error here.
if (bSupport)
{
break;
}
}
// pAddress is now a usable address.