如何使用 WPD 和设置 API 区分数码相机和其他设备

发布于 2024-12-02 00:02:17 字数 369 浏览 0 评论 0原文

我有 2 个任务:

a)区分数码相机和其他 MTP 设备,通过 IPortableDeviceManager::GetDeviceList 获得;

b) 我想通过设置 API 查找已连接的数码相机。我的想法是首先获取所有 USB 设备:

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

但这样做之后我已经没有想法了。具体来说,我不知道如何获取特定 USB 设备的 USB 接口描述符。我的意思是USB接口,而不是设置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, not what is called an interface in setup API.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒数 2024-12-09 00:02:17

以下是使用 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);
    }

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文