none
Known object identifier how to get the GUID(WPD知道对象标识符怎么获取GUID) RRS feed

  • 问题

  • 在进行MTP编程时,已知安卓设备中一个文件的object identifier,怎么获得它的GUID,我就是想拿这个GUID和PWD_OBJECT_CONNECT_FOLDER进行比较,看这个文件是不是一个文件夹,当然要是有其他的解决思路,麻烦大佬们留言。感激涕零。
    2017年11月12日 13:20

答案

  • GUID GetGUIDByObject(_In_ PCWSTR            objectID,
                      _In_ IPortableDevice*           device)
    {
    HRESULT                            hr = S_OK;
    ComPtr<IPortableDeviceProperties>     properties;
    ComPtr<IPortableDeviceValues>         objectProperties;
    ComPtr<IPortableDeviceContent>        content;
    ComPtr<IPortableDeviceKeyCollection>  propertiesToRead;

    if (SUCCEEDED(hr))
    {
    hr = device->Content(&content);
    if (FAILED(hr))
    {
    wprintf(L"! Failed to get IPortableDeviceContent from IPortableDevice, hr = 0x%lx\n", hr);
    }
    }

    if (SUCCEEDED(hr))
    {
    hr = content->Properties(&properties);
    if (FAILED(hr))
    {
    wprintf(L"! Failed to get IPortableDeviceProperties from IPortableDevice, hr = 0x%lx\n", hr);
    }
    }
    hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection,
    nullptr,
    CLSCTX_INPROC_SERVER,
    IID_PPV_ARGS(&propertiesToRead));
    if (SUCCEEDED(hr))
    {
    HRESULT tempHr = propertiesToRead->Add(WPD_OBJECT_PARENT_ID);
    if (FAILED(tempHr))
    {
    wprintf(L"! Failed to add WPD_OBJECT_PARENT_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
    }

    tempHr = propertiesToRead->Add(WPD_OBJECT_ORIGINAL_FILE_NAME);
    if (FAILED(tempHr))
    {
    wprintf(L"! Failed to add WPD_OBJECT_NAME to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
    }

    tempHr = propertiesToRead->Add(WPD_OBJECT_PERSISTENT_UNIQUE_ID);
    if (FAILED(tempHr))
    {
    wprintf(L"! Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
    }

    tempHr = propertiesToRead->Add(WPD_OBJECT_FORMAT);
    if (FAILED(tempHr))
    {
    wprintf(L"! Failed to add WPD_OBJECT_FORMAT to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
    }

    tempHr = propertiesToRead->Add(WPD_OBJECT_CONTENT_TYPE);
    if (FAILED(tempHr))
    {
    wprintf(L"! Failed to add WPD_OBJECT_CONTENT_TYPE to IPortableDeviceKeyCollection, hr= 0x%lx\n", tempHr);
    }
    }

    if (SUCCEEDED(hr))
    {
    hr = properties->GetValues(objectID,                // The object whose properties we are reading
    propertiesToRead.Get(),   // The properties we want to read
    &objectProperties);       // Driver supplied property values for the specified object
    if (FAILED(hr))
    {
    wprintf(L"! Failed to get all properties for object '%ws', hr= 0x%lx\n", objectID, hr);
    }
    }
    GUID    pValue = GUID_NULL;
    if (SUCCEEDED(hr))
    {

    hr = objectProperties->GetGuidValue(WPD_OBJECT_CONTENT_TYPE, &pValue);

    }
    return pValue;
    }

    I dig their own pit to fill, hoping to help developers behind

    • 已标记为答案 WriteDove 2018年1月21日 1:30
    2018年1月21日 1:21