/// <summary>
        /// Retrieves a string associated with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies which value to retrieve.</param>
        /// <param name="value">Receives the string.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetString(this IMFAttributes attributes, Guid guidKey, out string value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            value = null;

            int stringLength;

            HResult hr = attributes.GetStringLength(guidKey, out stringLength);

            if (hr.Failed())
            {
                return(hr);
            }

            StringBuilder sb = new StringBuilder(stringLength + 1);

            hr = attributes.GetString(guidKey, sb, sb.Capacity, out stringLength);
            if (hr.Failed())
            {
                return(hr);
            }

            value = sb.ToString();

            return(hr);
        }
Beispiel #2
0
        public static string GetString(this IMFAttributes obj, Guid key, string defaultValue = null)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (obj.GetStringLength(key, out var length).IsError)
            {
                return(defaultValue);
            }

            var s = new string('\0', (int)length);

            length++;
            obj.GetString(key, s, length, ref length).ThrowOnError();
            return(s);
        }
Beispiel #3
0
 public HResult GetStringLength(Guid guidKey, out int pcchLength)
 {
     return(m_Attribs.GetStringLength(guidKey, out pcchLength));
 }