c++qtmtpwpd

WPD Object Filename Truncated at '.'


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!


Solution

  • 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
    }