At the moment, I’m working on my library to support Media Transfer Protocol (MTP) devices via the Windows Portable Devices (WPD) API, so that future versions of RandFill will be able to use also smartphones as targets and not only Mass Storage Class (MSC) devices like plain USB flash drives.
And while it’s still far from finished, I’ve already written some lines of code to connect to the devices and read some of their capabilities.
The first stumbling block now was the event notification: Documentation on WPD is rather ‘manageable’, but enough to get it working — at least for plain MTP devices such as my Android and WindowsPhone smartphones: When adding files to it, for example, my program gets notfied. So far, so good.
But it didn’t work for plain MSC devices such as USB thumb drives. I knew that it was generally possible,
because RandFill currently watches those changes already, but it uses
for that, not the WPD API, of course.
My understanding was that WPD covers both modes, MTP and MSC. And it seemed plausible, because I could gather all kinds of data for both types of devices via the WPD API: Name, manufacturer, free storage capacity and so on.
But I was getting no event notifications on my USB flash drives and was running out of ideas:
- Tried different sticks, on several USB ports, on multiple computers; no change, so it wasn’t a hardware related problem.
- And the code and API wasn’t that complicated neither: Implementing a class with its methods, including
OnEvent(), registering the device for event notification; done.
- Not a multitude of flags to choose from, all plain and simple.
- And I checked all return values and results: Everything looked fine.
But I still received no event notifications in my program/library.
Then I discovered in the Explorer’s context menu of the USB thumb drive the item “Open as portable device”.
That opened a new window, but the content seemed no different (obviously, because beside the storage capabilty, a flash drive doesn’t offer any other services). But when I deleted a file in that view, my program/library got a notification event, yay!
OK, so one has to explicitly choose the WPD way when dealing with MSC devices. (Why exactly, I don’t know: Because Windows/Explorer/Shell uses different drivers by default, I guess.)
And that brings up another question: Will I be able to open the Explorer view in that mode by default? It seems so, taking heed of this text on StackOverflow.com, but I’ve not yet tried it; other points from my ‘todo’ list probably come before that (like writing/deleting files and folders).
Film & Television (26)
How To (41)
News & Announcements (22)
On Software (8)
Plans & Projects (8)