(guidKey.Guid);
}
///
/// Applies to: desktop apps | Metro style apps
Adds an attribute value with a specified key.
///
/// A that identifies the value to set. If this key already exists, the method overwrites the old value.
/// A that contains the attribute value. The method copies the value. The type must be one of the types listed in the enumeration.
/// The method returns an . Possible values include, but are not limited to, those in the following table.
| Return code | Description |
| The method succeeded. |
- E_OUTOFMEMORY
| Insufficient memory. |
- MF_E_INVALIDTYPE
| Invalid attribute type. |
?
///
/// This method checks whether the type is one of the attribute types defined in , and fails if an unsupported type is used. However, this method does not check whether the is the correct type for the specified attribute . (There is no programmatic way to associate attribute GUIDs with property types.) For a list of Media Foundation attributes and their data types, see Media Foundation Attributes.
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.
///
/// bb970346
/// HRESULT IMFAttributes::SetItem([In] const GUID& guidKey,[In] const PROPVARIANT& Value)
/// IMFAttributes::SetItem
public unsafe void Set(System.Guid guidKey, T value)
{
// Perform conversions to supported types
// int
// long
// string
// byte[]
// double
// ComObject
// Guid
if (typeof(T) == typeof(int) || typeof(T) == typeof(bool) || typeof(T) == typeof(byte) || typeof(T) == typeof(uint) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort) || typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte)
|| typeof(T).GetTypeInfo().IsEnum )
{
Set(guidKey, Convert.ToInt32(value));
return;
}
if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong))
{
Set(guidKey, Convert.ToInt64(value));
return;
}
if (typeof(T) == typeof(IntPtr))
{
Set(guidKey, ((IntPtr)(object)value).ToInt64());
return;
}
if (typeof(T) == typeof(System.Guid))
{
Set(guidKey, (System.Guid)(object)value);
return;
}
if (typeof(T) == typeof(string))
{
Set(guidKey, value.ToString());
return;
}
if (typeof(T) == typeof(double) || typeof(T) == typeof(float))
{
Set(guidKey, Convert.ToDouble(value));
return;
}
if (typeof(T) == typeof(byte[]))
{
var arrayValue = ((byte[])(object)value);
fixed (void* pBuffer = arrayValue)
SetBlob(guidKey, (IntPtr)pBuffer, arrayValue.Length);
return;
}
if (typeof(T).GetTypeInfo().IsValueType)
{
SetBlob(guidKey, (IntPtr)Interop.Fixed(ref value), SharpDX.Interop.SizeOf());
return;
}
if (typeof(T) == typeof(ComObject) || typeof(IUnknown).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()))
{
Set(guidKey, ((IUnknown)(object)value));
return;
}
throw new ArgumentException("The type of the value is not supported");
}
///
/// Applies to: desktop apps | Metro style apps
Adds an attribute value with a specified key.
///
/// A that identifies the value to set. If this key already exists, the method overwrites the old value.
/// A that contains the attribute value. The method copies the value. The type must be one of the types listed in the enumeration.
/// The method returns an . Possible values include, but are not limited to, those in the following table.
| Return code | Description |
| The method succeeded. |
- E_OUTOFMEMORY
| Insufficient memory. |
- MF_E_INVALIDTYPE
| Invalid attribute type. |
?
///
/// This method checks whether the type is one of the attribute types defined in , and fails if an unsupported type is used. However, this method does not check whether the is the correct type for the specified attribute . (There is no programmatic way to associate attribute GUIDs with property types.) For a list of Media Foundation attributes and their data types, see Media Foundation Attributes.
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.
///
/// bb970346
/// HRESULT IMFAttributes::SetItem([In] const GUID& guidKey,[In] const PROPVARIANT& Value)
/// IMFAttributes::SetItem
public unsafe void Set(MediaAttributeKey guidKey, T value)
{
Set(guidKey.Guid, value);
}
}
}