winapiwindows-servicesmtpwpd

Why am I not getting the WPD_OBJECT_ORIGINAL_FILE_NAME(i.e the filename) of the object on mtp device


I am using WPD (windows portable devices) API in my windows service, to transfer files from a folder on the mtp device to a designated folder on my hard disk.

For testing purposes I create xyzdata.txt file under a folder on the mtp device. So, when the code reaches a point where it does this:

    hr = content->Properties(&properties);
    if (SUCCEEDED(hr))
    {
        hr = GetStringValue(properties.Get(),
             selection,
             WPD_OBJECT_ORIGINAL_FILE_NAME,
             &originalFileName);
    }

The 'hr' is populated with "ERROR_BUSY"and originalFileName is not set at all. Is there a reason why the WPD_OBJECT_ORIGINAL_FILE_NAME may not be set for some objects or is it a problem with retrieving of data ?

Any help will be invaluable. If you need more code I shall post it here.

Edit:

Error code is,

hr = HRESULT_FROM_WIN32(ERROR_BUSY) : The requested resource is in use.

Also, the device is an android device. And sometimes when we plugin the usb cable back the file name is available. But this is rare. Please let me know whats happening


Solution

  • Found a solution.

    The problem was that GetStream() call was not finishing before I called GetStringValue().

    Since, GetStringValue() function call did not have any dependency on the GetStream(), I just reordered them and voila it all started to work.