11

In my project, I'm using the Windows Portable Device (WPD) API to enumerate the contents of a mobile device. WPD API Enumeration Guide. I'm able to enumerate over each object and view their properties as shown in the API programming guide. WPD API Properties Guide

However when I try to get an object's name that has a . within the name, the returned value is truncated at that .

HRESULT hr = objectProperties->GetStringValue(WPD_OBJECT_NAME, &strOriginalFileName);
if(FAILED(hr))
    return false;

PWSTR wideStr = strOriginalFileName;
char buffer[20];
wcstombs(buffer, wideStr, 20);

qDebug() << buffer;

So for example, an object (folder on the device) with the name of com.example is returned as com. This becomes an obvious issue when I'm trying to locate a specific filepath on the device.

I can't seem to figure out what's wrong. Am I misunderstanding how the filename actually is? Is example another property or something within the com object? I'm very confused.

EDIT: So I used the WPD API sample software to retrieve all the object properties of the com.example object and you can see that WPD itself cannot get the full folder name. enter image description here

Thanks for your time!

1 Answer 1

5
+25

The WPD Application Programming Reference refers following 3 NAMEs.

WPD_OBJECT_HINT_LOCATION_DISPLAY_NAME: A friendlier name, mostly intended for display

WPD_OBJECT_NAME: The name of the object on device.

WPD_OBJECT_ORIGINAL_FILE_NAME: The original filename of the object on device.

The MS code sample in C++ uses WPD_OBJECT_ORIGINAL_FILE_NAME to get to the actual file name (underneath the object) while transferring files from device to PC.

I modified the MS code sample (to enumerate object properties) and it showed me the actual file name (nothing truncated from the filename com.ef1.first.second)

Here is the image

I used:

    Windows Windows 7 Ultimate (without SP1)
    Visual Studio 2013
    Android 4.4.4 (Moto-E)
    Connection type: MTP
    Memory type: Internal Memory as well as External (SD Card)

I wouldn't be surprised if it doesn't work on some combination of Windows versions, Windows SDK versions, android versions, Connection types (MTP, PTP, USB Mass Storage).


Here is the part of code that I modified (and that is how it worked).

// Reads properties for the user specified object.
void ReadContentProperties(_In_ IPortableDevice* device)
{
   //.... Edited for brevity
   tempHr = propertiesToRead->Add(WPD_OBJECT_NAME);
   if (FAILED(tempHr))
   {
      wprintf(L"! Failed to add WPD_OBJECT_NAME to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
   }

   // Here is the added code
   tempHr = propertiesToRead->Add(WPD_OBJECT_ORIGINAL_FILE_NAME);
   if (FAILED(tempHr))
   {
      wprintf(L"! Failed to add WPD_OBJECT_ORIGINAL_FILE_NAME to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
   }
    //.... Edited for brevity
}
24
  • WPD_OBJECT_ORIGINAL_FILE_NAME is not a property of the object. The attached screenshot shows ALL of the associated properties to the object. I've been trying to get that property applied for days. It's on some files, but not others. (I believe). Any time I try to grab WPD_OBJECT_ORIGINAL_FILE_NAME the hr comes back as failed.
    – mrg95
    Nov 6, 2016 at 0:01
  • I had considered WPD_OBJECT_ORIGINAL_FILE_NAME as mandatory. May I know what file system your device is using? That may hint some more relevant information.
    – blackpen
    Nov 6, 2016 at 1:21
  • Just an android phone. OnePlus One to be exact, but I'm gonna need my software to support a variety of different phones/tablets.
    – mrg95
    Nov 6, 2016 at 5:48
  • I don't understand why your answer is being upvoted (no offense whatsoever). It's just not correct though. I've known about WPD_OBJECT_ORIGINAL_FILE_NAME from the very beginning and it's always come back as failed. Some followup would be nice :)
    – mrg95
    Nov 24, 2016 at 4:06
  • 1
    1) The object's name got truncated at first dot (Except when the object's name starts with a dot). 2) The original name always had full value (except for root level object's such as SD Card where it gave <Not Found>). 3) The object's name and original name may not always be same (object's name may be New Folder when original may be com.example) 4) With MTP, the windows file explorer doesn't seem to display empty folders till you actually put files in them (immaterial of whether they have a dot in their object's name or original file name or not).
    – blackpen
    Dec 4, 2016 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.