IMFAttributes::GetString method

Retrieves a wide-character string associated with a key.

Syntax

HRESULT GetString(
  REFGUID guidKey,
  LPWSTR  pwszValue,
  UINT32  cchBufSize,
  UINT32  *pcchLength
);

Parameters

guidKey

GUID that identifies which value to retrieve. The attribute type must be MF_ATTRIBUTE_STRING.

pwszValue

Pointer to a wide-character array allocated by the caller. The array must be large enough to hold the string, including the terminating NULL character. If the key is found and the value is a string type, the method copies the string into this buffer. To find the length of the string, call IMFAttributes::GetStringLength.

cchBufSize

The size of the pwszValue array, in characters. This value includes the terminating NULL character.

pcchLength

Receives the number of characters in the string, excluding the terminating NULL character. This parameter can be NULL.

Return Value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
S_OK
The method succeeded.
E_OUTOFMEMORY
The length of the string is too large to fit in a UINT32 value.
E_NOT_SUFFICIENT_BUFFER
The buffer is not large enough to hold the string.
MF_E_ATTRIBUTENOTFOUND
The specified key was not found.
MF_E_INVALIDTYPE
The attribute value is not a string.

Remarks

You can also use the IMFAttributes::GetAllocatedString method, which allocates the buffer to hold the string.

This interface is available on the following platforms if the Windows Media Format 11 SDK redistributable components are installed:

  • Windows XP with Service Pack 2 (SP2) and later.
  • Windows XP Media Center Edition 2005 with KB900325 (Windows XP Media Center Edition 2005) and KB925766 (October 2006 Update Rollup for Windows XP Media Center Edition) installed.

Examples

The following code example shows how to get an attribute whose value is a string.

HRESULT AttributeGetString(IMFAttributes *pAttributes)
{
    HRESULT hr = S_OK;
    UINT32 cchLength = 0;
    WCHAR *pString = NULL;

    hr = pAttributes->GetStringLength(MY_ATTRIBUTE, &cchLength);
    
    if (SUCCEEDED(hr))
    {
        pString = new WCHAR[cchLength + 1];
        if (pString == NULL)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = pAttributes->GetString(
            MY_ATTRIBUTE, pString, cchLength + 1, &cchLength);
    }

    if (pString)
    {
        delete [] pString;
    }
    return hr;
}

Requirements

   
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header mfobjects.h (include Mfidl.h)
Library Mfuuid.lib

See Also

Attributes and Properties

IMFAttributes

MF_ATTRIBUTE_TYPE