开发者

How to tell digital camera from other devices using WPD and using Setup API

I've got 2 tasks:

a) distinguish digital cameras from other MTP-devices, obtained by IPortableDeviceManager::GetDeviceList;

b) I want to find connected digital cameras with Setup API. My thought was to get all USB devices first:

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

But after doing that I've run out of ideas. Specifically, I can't figure out how to obtain USB interface descriptors for a specific USB device. I mean USB interfaces开发者_StackOverflow, not what is called an interface in setup API.

Thanks in advance.


Here's how it's done with WPD (assuming you have an already opened device named 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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜