Beispiel #1
0
        private void TestAttr()
        {
            short        w1, w2, w3;
            short        iIndex;
            const string v = "ItzaString";

            m_head.GetAttributeCountEx(0, out w1);

            byte[] b = Encoding.Unicode.GetBytes(v);
            m_head.AddAttribute(0, "asdf", out iIndex, AttrDataType.STRING, 0, b, b.Length);

            m_head.GetAttributeCountEx(0, out w2);

            Debug.Assert(w2 == w1 + 1);

            short        pNLen = 0;
            int          pDLen = 0;
            AttrDataType pType;
            short        pLang;

            m_head.GetAttributeByIndexEx(0, w1, null, ref pNLen, out pType, out pLang, null, ref pDLen);
            byte[] bb = new byte[pDLen];
            m_head.GetAttributeByIndexEx(0, w1, null, ref pNLen, out pType, out pLang, bb, ref pDLen);
            string        ss     = Encoding.Unicode.GetString(bb, 0, pDLen - 2);
            StringBuilder sbName = new StringBuilder(pNLen);

            byte[] bb2 = new byte[pDLen];
            m_head.GetAttributeByIndexEx(0, w1, sbName, ref pNLen, out pType, out pLang, bb2, ref pDLen);

            Debug.Assert(sbName.ToString() == "asdf" && pType == AttrDataType.STRING && pLang == 0 && v == Encoding.Unicode.GetString(bb2, 0, v.Length * 2));

            byte[] wm3 = BitConverter.GetBytes(4144);;
            m_head.ModifyAttribute(0, w1, AttrDataType.DWORD, 0, wm3, 4);

            byte[] bb4 = new byte[pDLen];
            m_head.GetAttributeByIndexEx(0, w1, null, ref pNLen, out pType, out pLang, bb4, ref pDLen);
            Debug.Assert(BitConverter.ToInt32(bb4, 0) == 4144);

            m_head.DeleteAttribute(0, w1);

            m_head.GetAttributeCountEx(0, out w3);
            Debug.Assert(w3 == w1);
        }
        private static MetadataField GetAttributeByIndex(IWMHeaderInfo3 header, int index)
        {
            StringBuilder     attributeName       = null;
            ushort            attributeNameLength = 0;
            WMT_ATTR_DATATYPE attributeDataType;
            ushort            langIndex = 0;

            byte[] attributeValue       = null;
            uint   attributeValueLength = 0;

            header.GetAttributeByIndexEx(
                StreamNumber,
                (ushort)index,
                attributeName,
                ref attributeNameLength,
                out attributeDataType,
                out langIndex,
                attributeValue,
                ref attributeValueLength);

            attributeName  = new StringBuilder(attributeNameLength, attributeNameLength);
            attributeValue = new byte[attributeValueLength];

            header.GetAttributeByIndexEx(
                StreamNumber,
                (ushort)index,
                attributeName,
                ref attributeNameLength,
                out attributeDataType,
                out langIndex,
                attributeValue,
                ref attributeValueLength);

            object value = ParseAttributeValue(attributeValue, attributeDataType);

            MetadataField field = new MetadataField(attributeName.ToString(), value);

            return(field);
        }