I want to get all root directories for MTP USB devices (I can identify them as GUID) from WPD API. So my question is: How I can do this? Any code snippets will be appreciated.
1 Answers
I beleave you should read the Windows portable devices guide: https://msdn.microsoft.com/en-us/library/windows/desktop/dd389005(v=vs.85).aspx as far as this task is common and similar tasks described here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd319330(v=vs.85).aspx and there is a sample solution you can try to compile and debug: https://code.msdn.microsoft.com/windowsdesktop/Portable-Devices-COM-API-fd4a5f7d
Shortly, you have to create IPortableDeviceContent object, then call EnumObjects method from it with id WPD_DEVICE_OBJECT_ID (it's a macro for ROOT of current device).
You will obtain objects ids that way, then you have to iterate over them and request properties (WPD_OBJECT_CONTENT_TYPE in your case) of each object by id.
Objects with WPD_OBJECT_CONTENT_TYPE == WPD_CONTENT_TYPE_FOLDER are folders.

- 1,207
- 8
- 17