Question

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, not what is called an interface in setup API.

Thanks in advance.

Était-ce utile?

La solution

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);
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top