Beispiel #1
0
        /// <summary>
        /// Set an attribute specifying a stream number. Wraps IWMHeaderInfo.SetAttribute
        /// </summary>
        /// <param name="StreamNumber">Stream number. Zero for file level attributes.</param>
        /// <param name="attr">Attribute to set. <see cref="Yeti.WMFSDK.WM_Attr"/></param>
        public void SetAttribute(int StreamNumber, WM_Attr attr)
        {
            object obj;
            ushort size;

            switch (attr.DataType)
            {
            case WMT_ATTR_DATATYPE.WMT_TYPE_STRING:
                byte[] arr = Encoding.Unicode.GetBytes((string)attr.Value + (char)0);
                obj  = arr;
                size = (ushort)arr.Length;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_BOOL:
                obj  = (uint)((bool)attr ? 1 : 0);
                size = 4;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_BINARY:
                obj  = (byte[])attr.Value;
                size = (ushort)((byte[])obj).Length;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_DWORD:
                obj  = (uint)attr;
                size = 4;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_QWORD:
                obj  = (ulong)attr;
                size = 8;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_WORD:
                obj  = (ushort)attr;
                size = 2;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_GUID:
                obj  = (Guid)attr;
                size = (ushort)Marshal.SizeOf(typeof(Guid));
                break;

            default:
                throw new ArgumentException("Invalid data type", "attr");
            }
            GCHandle h = GCHandle.Alloc(obj, GCHandleType.Pinned);

            try
            {
                m_HeaderInfo.SetAttribute((ushort)StreamNumber, attr.Name, attr.DataType, h.AddrOfPinnedObject(), size);
            }
            finally
            {
                h.Free();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Set file level attributes
 /// </summary>
 /// <param name="attr">Attribute to set <see cref="Yeti.WMFSDK.WM_Attr"/></param>
 public void SetAttribute(WM_Attr attr)
 {
     SetAttribute(0, attr);
 }
Beispiel #3
0
 /// <summary>
 /// Set an attribute specifying a stream number. Wraps IWMHeaderInfo.SetAttribute
 /// </summary>
 /// <param name="StreamNumber">Stream number. Zero for file level attributes.</param>
 /// <param name="attr">Attribute to set. <see cref="Yeti.WMFSDK.WM_Attr"/></param>
 public void SetAttribute(int StreamNumber, WM_Attr attr)
 {
     object obj;
     ushort size;
     switch (attr.DataType)
     {
         case WMT_ATTR_DATATYPE.WMT_TYPE_STRING:
             byte[] arr = Encoding.Unicode.GetBytes((string)attr.Value + (char)0);
             obj = arr;
             size = (ushort)arr.Length;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_BOOL:
             obj = (uint)((bool)attr ? 1 : 0);
             size = 4;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_BINARY:
             obj = (byte[])attr.Value;
             size = (ushort)((byte[])obj).Length;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_DWORD:
             obj = (uint)attr;
             size = 4;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_QWORD:
             obj = (ulong)attr;
             size = 8;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_WORD:
             obj = (ushort)attr;
             size = 2;
             break;
         case WMT_ATTR_DATATYPE.WMT_TYPE_GUID:
             obj = (Guid)attr;
             size = (ushort)Marshal.SizeOf(typeof(Guid));
             break;
         default:
             throw new ArgumentException("Invalid data type", "attr");
     }
     GCHandle h = GCHandle.Alloc(obj, GCHandleType.Pinned);
     try
     {
         m_HeaderInfo.SetAttribute((ushort)StreamNumber, attr.Name, attr.DataType, h.AddrOfPinnedObject(), size);
     }
     finally
     {
         h.Free();
     }
 }
Beispiel #4
0
 /// <summary>
 /// Set file level attributes
 /// </summary>
 /// <param name="attr">Attribute to set <see cref="Yeti.WMFSDK.WM_Attr"/></param>
 public void SetAttribute(WM_Attr attr)
 {
     SetAttribute(0, attr);
 }