在我的项目中,我使用 Windows 可移植设备 (WPD) API 来枚举移动设备的内容。 WPD API Enumeration Guide .我能够枚举每个对象并查看它们的属性,如 API 编程指南中所示。 WPD API Properties Guide
但是,当我尝试获取具有 .
的对象名称时在名称中,返回值在 .
处被截断
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;
例如,名称为 com.example
的对象(设备上的文件夹)返回为 com
.当我试图在设备上查找特定文件路径时,这就成了一个明显的问题。
我似乎无法弄清楚出了什么问题。我误解了文件名的实际含义吗?是example
com
中的其他属性(property)或其他东西目的?我很困惑。
编辑: 所以我使用 WPD API 示例软件来检索 com.example 对象的所有对象属性,您可以看到 WPD 本身无法获取完整的文件夹名称。
感谢您的宝贵时间!
最佳答案
WPD Application Programming Reference引用以下 3 个名称。
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.
C++ 中的 MS 代码示例使用 WPD_OBJECT_ORIGINAL_FILE_NAME 在将文件从设备传输到 PC 时获取实际文件名(在对象下方)。
我修改了 MS 代码示例(以枚举对象属性),它向我显示了实际的文件名(没有从文件名 com.ef1.first.second
中截断)
我用过:
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
}
关于c++ - WPD 对象文件名在 '.' 处被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40374361/