WPD get media dimensions

0

I want to get the width and hight of a image file on a WPD via IPortableDeviceValues.

According to the Windows Dev Center every object whose type is WPD_CONTENT_TYPE_IMAGE (which they are) requires to provide WPD_MEDIA_WIDTH/WPD_MEDIA_HEIGHT but I always get a error.

HRESULT MyPortableDevice::getIntValue(IPortableDeviceProperties* properties, PCWSTR objectID, const PROPERTYKEY& key, DWORD* value)
{

ComPtr<IPortableDeviceValues>        objectProperties;
ComPtr<IPortableDeviceKeyCollection> propertiesToRead;

HRESULT hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection,
                              nullptr,
                              CLSCTX_INPROC_SERVER,
                              IID_PPV_ARGS(&propertiesToRead));

if (SUCCEEDED(hr)) {
    HRESULT tempHr = S_OK;
    tempHr = propertiesToRead->Add(key);      
}

if (SUCCEEDED(hr)) {
    hr = properties->GetValues(objectID,                
                               propertiesToRead.Get(),  
                               &objectProperties); 
}   

if (SUCCEEDED(hr)) {

    ULONG intValue = 0;
    hr = objectProperties->GetUnsignedIntegerValue(key, &intValue);

    if (SUCCEEDED(hr)) {          
        value = &intValue;
        intValue = 0;
    }            
}

return hr;

I always get a error value from

hr = objectProperties->GetUnsignedIntegerValue(key, &intValue);

hr = 0x80070490 and I can't find this error code here

Does anyone know what's wrong?

c++
wpd
asked on Stack Overflow Dec 20, 2017 by RobRobRob • edited Dec 20, 2017 by RobRobRob

1 Answer

1

The error you got is: Error code: (HRESULT) 0x80070490 (2147943568) - Element not found.

The reason you got this error most probably is that actually phone apps developers usually just ignore some of properties.

I have connected my phone to PC and checked some images with WPD Information Tool , and I get only such fields for .jpg screenshot: enter image description here

I think in most cases you need to read content of the picture to stream and check it's parameters directly. Maybe in some formats you can read only some "header" part and get WIDTH and HEIGHT from there.

answered on Stack Overflow Jan 17, 2018 by Arthur Bulakaiev

User contributions licensed under CC BY-SA 3.0