如何使用WPD和使用Setup API从其他设备告知数码相机

时间:2011-08-29 19:00:24

标签: windows wpd setupapi

我有两项任务:

a)区分数码相机与其他MTP设备,由IPortableDeviceManager :: GetDeviceList获取;

b)我想找到带有Setup API的连接数码相机。我的想法是首先获得所有USB设备:

SetupDiGetClassDevs( &GUID_DEVINTERFACE_USB_DEVICE, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);

但在这之后我已经没有想法了。具体来说,我无法弄清楚如何获取特定USB设备的USB接口描述符。我指的是USB接口,而不是设置API中的所谓接口。

提前致谢。

1 个答案:

答案 0 :(得分:0)

以下是使用WPD的方法(假设您已经打开了一个名为wpdDev的设备):

    IPortableDeviceCapabilities* pCaps = 0;
    IPortableDevice* pWpdDev = wpdDev.getWpdDev();
    hr = pWpdDev->Capabilities(&pCaps);
    if (hr != S_OK || !pCaps)
    {
        Logger() << "Failed to obtain capabilities for device" << CString::fromUtf16(deviceId).toUtf8().getData();
        continue;
    }
    IPortableDevicePropVariantCollection* pCategories = 0;
    hr = pCaps->GetFunctionalCategories(&pCategories);
    if (hr != S_OK || !pCategories)
    {
        Logger() << "Failed to obtain functional categories for device" << CString::fromUtf16(deviceId).toUtf8().getData();
        continue;
    }
    DWORD numCategories = 0;
    hr = pCategories->GetCount(&numCategories);
    if (hr != S_OK || !numCategories)
    {
        Logger() << "Failed to obtain functional categories for device" << CString::fromUtf16(deviceId).toUtf8().getData();
        continue;
    }
    bool isCamera = wpdDev.vendor() == CANON_VENDOR_ID;
    //Просматриваем все категории и проверяем, может ли устройство выполнять функции камеры
    for (size_t idx = 0; idx < numCategories; ++idx)
    {
        PROPVARIANT pv = {0};
        PropVariantInit(&pv);
        hr = pCategories->GetAt(idx, &pv);
        if (hr == S_OK)
        // We have a functional category.  It is assumed that
        // functional categories are returned as VT_CLSID
        // VarTypes.
            if ((pv.puuid != NULL) && (pv.vt == VT_CLSID))
                if (IsEqualGUID(WPD_FUNCTIONAL_CATEGORY_STILL_IMAGE_CAPTURE, *(pv.puuid)))
                    isCamera = true;
        PropVariantClear(&pv);
    }