locked
How to pass string or custom struct to WinRT MFT object

    Question

  • CGrayscale sample used as example.

    HRESULT CGrayscale::SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration)
    {
    HRESULT hr = S_OK;
    
    HSTRING key;
    WindowsCreateString(L"{67CBEF12-6967-4744-9D44-B0AD9023CA42}", 38, &key);
    Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> spSetting;
    pConfiguration->QueryInterface(IID_PPV_ARGS(&spSetting));
    
    //return S_OK;
    
    boolean found;
    spSetting->HasKey(key, &found);
    
    if (found)
    {
        IInspectable* value;
        spSetting->Lookup(key, &value);
            Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IReference<ABI::Windows::Foundation::Rect>> ref;
        value->QueryInterface(IID_PPV_ARGS(&ref));
        ABI::Windows::Foundation::Rect d2drect;
        ref->get_Value(&d2drect);
    }

    This sample worked for Rect, but I'm not able to use HSTRING for ref or any other type.

    I need to send string (bad) or my own struct (good) to set filter parameters.


    Roman

    • Moved by Jesse Jiang Tuesday, January 08, 2013 5:45 AM (From:Building Windows Store apps with C# or VB )
    Sunday, January 06, 2013 12:02 PM

Answers

  • Hi,

    I found a pieces of code to set and get the PropertySet

    Set

                PropertySet configuration = new PropertySet();
                configuration.Add("effect", effectName);
                outputVideo.AddVideoEffect("PolarTransform.PolarEffect", true, configuration);
    
    

    Get

    HRESULT CPolarEffect::SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration)
    {
        HRESULT hr = S_OK;
    
        if(pConfiguration)
        {
            Microsoft::WRL::ComPtr<IInspectable> spInsp;
            Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> spSetting;
            Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IPropertyValue> spPropVal;
    
            hr = pConfiguration->QueryInterface(IID_PPV_ARGS(&spSetting));
            if (FAILED(hr))
            {
                hr = E_FAIL;
                goto done;
            }
    
            HStringReference strKey(L"effect");
            hr = spSetting->Lookup(strKey.Get(), spInsp.ReleaseAndGetAddressOf());
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            hr = spInsp.As(&spPropVal);
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            HString strEffectName;
            hr = spPropVal->GetString(strEffectName.GetAddressOf());
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            LPCWSTR pszEffectName = WindowsGetStringRawBuffer(strEffectName.Get(), nullptr);
            if (pszEffectName == nullptr)
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            if (wcscmp(pszEffectName, L"Fisheye") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::FisheyeRadius;
                m_pThetaTransformFn = CPolarEffect::DefaultTheta;
            }
            else if (wcscmp(pszEffectName, L"Pinch") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::PinchRadius;
                m_pThetaTransformFn = CPolarEffect::DefaultTheta;
            }
            else if (wcscmp(pszEffectName, L"Warp") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::DefaultRadius;
                m_pThetaTransformFn = CPolarEffect::WarpTheta;
            }
            else
            {
                hr = E_INVALIDARG;
                goto done;
            }
        }
    
    done:
        return hr;
    }

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Friday, January 11, 2013 3:28 AM
    Tuesday, January 08, 2013 6:28 AM

All replies

  • Hi,

    I found a pieces of code to set and get the PropertySet

    Set

                PropertySet configuration = new PropertySet();
                configuration.Add("effect", effectName);
                outputVideo.AddVideoEffect("PolarTransform.PolarEffect", true, configuration);
    
    

    Get

    HRESULT CPolarEffect::SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration)
    {
        HRESULT hr = S_OK;
    
        if(pConfiguration)
        {
            Microsoft::WRL::ComPtr<IInspectable> spInsp;
            Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> spSetting;
            Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IPropertyValue> spPropVal;
    
            hr = pConfiguration->QueryInterface(IID_PPV_ARGS(&spSetting));
            if (FAILED(hr))
            {
                hr = E_FAIL;
                goto done;
            }
    
            HStringReference strKey(L"effect");
            hr = spSetting->Lookup(strKey.Get(), spInsp.ReleaseAndGetAddressOf());
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            hr = spInsp.As(&spPropVal);
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            HString strEffectName;
            hr = spPropVal->GetString(strEffectName.GetAddressOf());
            if(FAILED(hr))
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            LPCWSTR pszEffectName = WindowsGetStringRawBuffer(strEffectName.Get(), nullptr);
            if (pszEffectName == nullptr)
            {
                hr = E_INVALIDARG;
                goto done;
            }
    
            if (wcscmp(pszEffectName, L"Fisheye") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::FisheyeRadius;
                m_pThetaTransformFn = CPolarEffect::DefaultTheta;
            }
            else if (wcscmp(pszEffectName, L"Pinch") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::PinchRadius;
                m_pThetaTransformFn = CPolarEffect::DefaultTheta;
            }
            else if (wcscmp(pszEffectName, L"Warp") == 0)
            {
                m_pRadiusTransformFn = CPolarEffect::DefaultRadius;
                m_pThetaTransformFn = CPolarEffect::WarpTheta;
            }
            else
            {
                hr = E_INVALIDARG;
                goto done;
            }
        }
    
    done:
        return hr;
    }

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Friday, January 11, 2013 3:28 AM
    Tuesday, January 08, 2013 6:28 AM
  • Work great for strings, thank you!

    Any ideas how to pass custom struct?


    Roman

    Saturday, January 12, 2013 8:51 AM