IMFAttributes::GetString method (mfobjects.h)
Retrieves a wide-character string associated with a key.
Syntax
HRESULT GetString(
[in] REFGUID guidKey,
[out] LPWSTR pwszValue,
[in] UINT32 cchBufSize,
[out] UINT32 *pcchLength
);
Parameters
[in] guidKey
GUID that identifies which value to retrieve. The attribute type must be MF_ATTRIBUTE_STRING.
[out] 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.
[in] cchBufSize
The size of the pwszValue array, in characters. This value includes the terminating NULL character.
[out] 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 |
---|---|
|
The method succeeded. |
|
The length of the string is too large to fit in a UINT32 value. |
|
The buffer is not large enough to hold the string. |
|
The specified key was not found. |
|
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
Requirement | Value |
---|---|
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 |