IWMDMEnumDevice::Next 方法 (mswmdm.h)

Next 方法返回指向下一个设备的指针,由 IWMDMDevice 接口表示。

语法

HRESULT Next(
  [in]  ULONG       celt,
  [out] IWMDMDevice **ppDevice,
  [out] ULONG       *pceltFetched
);

参数

[in] celt

请求的设备数。

[out] ppDevice

指向调用方分配的 IWMDMDevice 接口指针数组的指针。 此数组的大小必须为 IWMDMDevice *[celt]。 调用方在使用这些接口时必须释放这些接口。 若要避免分配整个数组,只需传入指向 IWMDMDevice 接口的指针的地址,如备注中所示。

[out] pceltFetched

指向一个变量的指针,该变量接收) 返回的设备数 (接口数。

返回值

该方法返回 HRESULT。 Windows Media 设备管理器 中的所有接口方法都可以返回以下任一类错误代码:

  • 标准 COM 错误代码
  • 转换为 HRESULT 值的 Windows 错误代码
  • Windows Media 设备管理器错误代码
有关可能错误代码的广泛列表,请参阅 错误代码

注解

返回的设备接口 () 基于缓存的设备列表。 如果附加或删除了即插即用设备,则当前枚举器不会反映这一点,因此,“下一步”将基于缓存列表返回设备。 应用程序应通过调用 IWMDeviceManager::EnumDevices 获取设备刷新列表来获取新的枚举器对象。

如果一次只想检索单个接口,则无需为此方法分配数组,如以下代码所示:


// Get a device enumerator to examine each device.
CComPtr<IWMDeviceManager2> pIWMDevMgr2;
hr = m_IWMDeviceMgr->QueryInterface (__uuidof(IWMDeviceManager2), (void**) &pIWMDevMgr2);
if (hr == S_OK)
{
    // TODO: Display a message that the application retrieved IWMDeviceManager2.
}
else
{
    // TODO: Display a message that the application was not able to 
    // retrieve IWMDeviceManager2 in EnumDevices.
    return hr;
}

// Enumerate through the devices using the faster EnumDevices2 plug-and-play method.
CComPtr<IWMDMEnumDevice> pEnumDevice;
hr = pIWMDevMgr2->EnumDevices2(&pEnumDevice);
if (hr != S_OK)
{
    //.TODO: Display a message that an error occurred in calling EnumDevices2.
    return hr;
}

// Enumerate through devices.
IWMDMDevice *pIWMDMDevice;
ULONG ulFetched = 0;
while(pEnumDevice->Next(1, &pIWMDMDevice, &ulFetched) == S_OK)
{
    if (ulFetched != 1)
    {
        return E_FAIL;
    }
    // Do some stuff here....
}

要求

要求
目标平台 Windows
标头 mswmdm.h
Library Mssachlp.lib

另请参阅

枚举设备

IWMDMEnumDevice 接口

IWMDeviceManager::EnumDevices