c++ - WindowsPortableDevice IPortableDeviceContent::Delete 导致我的设备挂起。我该如何解决这个问题?
问题描述
我一直在尝试为我的 Android 手机内容构建一个文件浏览器,以根据我的需要进行优化。由于 FindFirstFile api 不适用于 MTP 设备,我不得不学习 Windows Portable Device Api。
我遇到了很多障碍,但大多数事情都奏效了:
- 枚举设备和文件
- 获取文件属性
- 重新命名文件
- 创建文件夹
- 复制DeviceFileToPc
- 复制PcFileToDevice
我现在唯一的障碍是删除文件。我完美地遵循了 MSDN 示例,但仍然遇到了问题。问题是当我尝试删除文件时,文件被删除但设备挂起并且没有响应。那时甚至 Windows 资源管理器都无法访问它。我必须断开并重新连接设备。但是 Windows 资源管理器能够删除设备上的文件没有问题。
这是我的代码
typedef const wchar_t *string_t;
bool wpd::Device::deleteFile(string_t file_id)
{
PROPVARIANT file ={};
IPortableDevicePropVariantCollection *filesToDelete = newIPortableDevicePropVariantCollection(); // Calls CoCreateInstance
IPortableDeviceContent *devContentMgr;
file.vt = VT_LPWSTR;
file.pwszVal = (LPWSTR)file_id;
filesToDelete->Add(&file);
// IPortableDevice *dev initialized in constructor
dev->Content(&devContentMgr);
HRESULT hr = devContentMgr->Delete(PORTABLE_DEVICE_DELETE_NO_RECURSION,filesToDelete,NULL);
filesToDelete->Release();
devContentMgr->Release();
return SUCCEEDED(hr);
}
请注意,我在 Windows Xp 上执行此操作。
解决方案
推荐阅读
- docker - 无法创建服务器 TCP 侦听套接字 *:6383 绑定:无法在 docker 上的 redis 集群中分配请求的地址(在 Windows 中)
- jpa - 具有空值的复合键的 JPA 保存方法
- c++ - 如何在 c++ std::system() 中插入多个变量?
- amazon-web-services - AWS Glue 数据目录,具有 S3 文件上的分区表和分区中的不同架构
- c# - 如何将索引值添加到来自另一种不同形式的列表视图中?
- bash - 使用 getopts 捕获无法识别的选项和未指定的选项值
- python - Discord.ext 任务循环的执行速度比预期的要快
- java - 具有特定条件计数的 Mongo DB 聚合并按输出投影的日期范围过滤不能按预期工作
- python - 无法在heroku服务中推送css
- node.js - 反应 Nodejs JWT 或会话