首页 > 解决方案 > WindowsPortableDevice IPortableDeviceContent::Delete 导致我的设备挂起。我该如何解决这个问题?

问题描述

我一直在尝试为我的 Android 手机内容构建一个文件浏览器,以根据我的需要进行优化。由于 FindFirstFile api 不适用于 MTP 设备,我不得不学习 Windows Portable Device Api。

我遇到了很多障碍,但大多数事情都奏效了:

我现在唯一的障碍是删除文件。我完美地遵循了 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 上执行此操作。

标签: c++windowsdeviceportabilitymtp

解决方案


推荐阅读