IPortableDeviceManager::GetDevices method (portabledeviceapi.h)
Retrieves a list of portable devices connected to the computer.
HRESULT GetDevices( [in, out] LPWSTR *pPnPDeviceIDs, [in, out] DWORD *pcPnPDeviceIDs );
[in, out] pPnPDeviceIDs
A caller-allocated array of string pointers that holds the Plug and Play names of all of the connected devices. To learn the required size for this parameter, first call this method with this parameter set to NULL and pcPnPDeviceIDs set to zero, and then allocate a buffer according to the value retrieved by pcPnPDeviceIDs. These names can be used by IPortableDevice::Open to create a connection to a device.
[in, out] pcPnPDeviceIDs
On input, the number of values that pPnPDeviceIDs can hold. On output, a pointer to the number of devices actually written to pPnPDeviceIDs.
The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.
||The method succeeded.|
||At least one of the required arguments was a NULL pointer.|
||The pPnPDeviceIDs buffer is too small to hold all the values requested, but pcPnPDeviceIDs values have been written to pPnPDeviceIDs.|
The list of devices is generated when the device manager is instantiated; it does not refresh as devices connect and disconnect. To refresh the list of connected devices, call RefreshDeviceList.
The API allocates the memory for each string pointed to by the pPnPDeviceIDs array. Once your application no longer needs these strings, it must iterate through this array and free the associated memory by calling the CoTaskMemFree function.