Поделиться через


Enumerating WPD devices (Part 2)

In part 1 we obtained a list of available WPD devices (the device paths to be precise). In this part, we'll use this device path with the IPortableDeviceManager interface to get basic information about the device.

 // cdwDevices contains the number of connected devices
// and also provides the length of ppszDeviceListArray
for (DWORD i = 0; i < cdwDevices; i++)
{
    LPCWSTR pwszDevicePath = ppszDeviceListArray[i];

    // These methods require caller-allocated buffers
    const DWORD MAX_CHARS = 255;
    WCHAR wszInfo[MAX_CHARS + 1] = {0};

    printf("Device %d:\n", i + 1);
  
    // Retrieve the device friendly name
    hr = spDevMgr->GetDeviceFriendlyName(pwszDevicePath, wszInfo, MAX_CHARS);
    if (hr == S_OK)
    {
        printf("\tFriendly Name: %ws\n", wszInfo);
    }

    // Retrieve the device description
    hr = spDevMgr->GetDeviceDescription(pwszDevicePath, wszInfo, MAX_CHARS);
    if (hr == S_OK)
    {
        printf("\tDescription: %ws\n", wszInfo);
    }

    // Retrieve the device manufacturer
    hr = spDevMgr->GetDeviceManufacturer(pwszDevicePath, wszInfo, MAX_CHARS);
    if (hr == S_OK)
    {
        printf("\tManufacturer: %ws\n", wszInfo);
    }
}

 IPortableDeviceManager also exposes a GetDeviceProperty method meant for use by device vendors that add additional properties on the device node via their INF.

[Thanks to CooperP for the stimulus to revive this blog :)]

Comments

  • Anonymous
    August 11, 2013
    Great tutorial ! But, a device has many informations such as : Serial number , IMEI (mobile phone),kernel vesion ... So, how can I take these informations Thank,