The PropertyValue_r structure is an encoding of the PropertyValue data structure
Esempio n. 1
0
        /// <summary>
        /// Parse PropertyValue_r structure.
        /// </summary>
        /// <param name="ptr">A pointer points to memory allocated.</param>
        /// <returns>Instance of PropertyValue_r structure.</returns>
        public static PropertyValue_r ParsePropertyValue_r(IntPtr ptr)
        {
            PropertyValue_r protertyValue = new PropertyValue_r();

            int offset = 0;

            protertyValue.PropTag = (uint)Marshal.ReadInt32(ptr, offset);
            offset += 4;

            protertyValue.Reserved = (uint)Marshal.ReadInt32(ptr, offset);
            offset += 4;

            protertyValue.Value = ParsePROP_VAL_UNION(new IntPtr(ptr.ToInt32() + offset), (PropertyType)(protertyValue.PropTag & 0x0000FFFF));

            return(protertyValue);
        }
        /// <summary>
        /// Parse PropertyValue_r structure.
        /// </summary>
        /// <param name="ptr">A pointer points to the allocated memory.</param>
        /// <returns>Instance of PropertyValue_r structure.</returns>
        public static PropertyValue_r ParsePropertyValue_r(IntPtr ptr)
        {
            PropertyValue_r protertyValue = new PropertyValue_r();

            int offset = 0;

            protertyValue.PropTag = (uint)Marshal.ReadInt32(ptr, offset);
            offset += sizeof(uint);

            protertyValue.Reserved = (uint)Marshal.ReadInt32(ptr, offset);
            offset += sizeof(uint);

            IntPtr newPtr = new IntPtr(ptr.ToInt32() + offset);
            protertyValue.Value = ParsePROP_VAL_UNION(newPtr, (PropertyTypeValue)(protertyValue.PropTag & 0x0000FFFF));

            return protertyValue;
        }
Esempio n. 3
0
        /// <summary>
        /// Allocate memory for the specific property values.
        /// </summary>
        /// <param name="propertyValue">PropertyValue_r instance.</param>
        /// <returns>A pointer points to memory allocated.</returns>
        public static IntPtr AllocPropertyValue_r(PropertyValue_r propertyValue)
        {
            IntPtr ptr    = Marshal.AllocHGlobal(16);
            int    offset = 0;

            Marshal.WriteInt32(ptr, (int)propertyValue.PropTag);
            offset += sizeof(uint);
            Marshal.WriteInt32(ptr, offset, (int)propertyValue.Reserved);
            offset += sizeof(uint);

            PropertyType proptype = (PropertyType)(0x0000FFFF & propertyValue.PropTag);

            switch (proptype)
            {
            case PropertyType.PtypInteger16:
            {
                Marshal.WriteInt16(ptr, offset, propertyValue.Value.I);
                break;
            }

            case PropertyType.PtypInteger32:
            {
                Marshal.WriteInt32(ptr, offset, propertyValue.Value.L);
                break;
            }

            case PropertyType.PtypBoolean:
            {
                Marshal.WriteInt16(ptr, offset, (short)propertyValue.Value.B);
                break;
            }

            case PropertyType.PtypString8:
            {
                IntPtr strA = Marshal.StringToHGlobalAnsi(propertyValue.Value.LpszA);
                Marshal.WriteInt32(ptr, offset, strA.ToInt32());
                break;
            }

            case PropertyType.PtypBinary:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.Bin.Cb);
                offset += sizeof(uint);
                IntPtr lpb = Marshal.AllocHGlobal((int)propertyValue.Value.Bin.Cb);
                for (int i = 0; i < propertyValue.Value.Bin.Cb; i++)
                {
                    Marshal.WriteByte(lpb, i, propertyValue.Value.Bin.Lpb[i]);
                }

                Marshal.WriteInt32(ptr, offset, lpb.ToInt32());
                break;
            }

            case PropertyType.PtypString:
            {
                IntPtr strW = Marshal.StringToHGlobalAnsi(propertyValue.Value.LpszW);
                Marshal.WriteInt32(ptr, offset, strW.ToInt32());
                break;
            }

            case PropertyType.PtypGuid:
            {
                IntPtr guid = Marshal.AllocHGlobal(16);
                for (int i = 0; i < 16; i++)
                {
                    Marshal.WriteByte(guid, i, propertyValue.Value.Guid[0].Ab[i]);
                }

                Marshal.WriteInt32(ptr, offset, guid.ToInt32());
                break;
            }

            case PropertyType.PtypTime:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.FileTime.LowDateTime);
                offset += sizeof(uint);
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.FileTime.HighDateTime);
                break;
            }

            case PropertyType.PtypErrorCode:
            {
                Marshal.WriteInt32(ptr, offset, propertyValue.Value.ErrorCode);
                break;
            }

            case PropertyType.PtypMultipleInteger16:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVi.Values);
                offset += sizeof(uint);
                IntPtr lpi = Marshal.AllocHGlobal((int)(propertyValue.Value.MVi.Values * sizeof(short)));
                for (int i = 0; i < propertyValue.Value.MVi.Values; i++)
                {
                    Marshal.WriteInt16(lpi, i * sizeof(short), propertyValue.Value.MVi.Lpi[i]);
                }

                Marshal.WriteInt32(ptr, offset, lpi.ToInt32());
                break;
            }

            case PropertyType.PtypMultipleInteger32:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVl.Values);
                offset += sizeof(uint);
                IntPtr lpl = Marshal.AllocHGlobal((int)(propertyValue.Value.MVl.Values * sizeof(int)));
                for (int i = 0; i < propertyValue.Value.MVl.Values; i++)
                {
                    Marshal.WriteInt32(lpl, i * sizeof(int), propertyValue.Value.MVl.Lpl[i]);
                }

                Marshal.WriteInt32(ptr, offset, lpl.ToInt32());
                break;
            }

            case PropertyType.PtypMultipleString8:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVszA.Values);
                offset += sizeof(uint);
                IntPtr lppszA = Marshal.AllocHGlobal((int)(propertyValue.Value.MVszA.Values * 4));
                for (int i = 0; i < propertyValue.Value.MVszA.Values; i++)
                {
                    Marshal.WriteInt32(lppszA, 4 * i, Marshal.StringToHGlobalAnsi(propertyValue.Value.MVszA.LppszA[i]).ToInt32());
                }

                Marshal.WriteInt32(ptr, offset, lppszA.ToInt32());
                break;
            }

            case PropertyType.PtypMultipleBinary:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVbin.Values);
                offset += sizeof(uint);
                IntPtr mvbin = Marshal.AllocHGlobal((int)(propertyValue.Value.MVbin.Values * 8));
                for (int i = 0; i < propertyValue.Value.MVbin.Values; i++)
                {
                    Marshal.WriteInt32(mvbin, (int)propertyValue.Value.MVbin.Lpbin[0].Cb);
                    IntPtr lpb = Marshal.AllocHGlobal((int)propertyValue.Value.MVbin.Lpbin[0].Cb);
                    for (int j = 0; j < propertyValue.Value.MVbin.Lpbin[0].Cb; j++)
                    {
                        Marshal.WriteByte(lpb, j, propertyValue.Value.MVbin.Lpbin[0].Lpb[j]);
                    }

                    Marshal.WriteInt32(mvbin, sizeof(uint), lpb.ToInt32());
                    mvbin = new IntPtr(mvbin.ToInt32() + 8);
                }

                Marshal.WriteInt32(ptr, offset, mvbin.ToInt32());
                break;
            }

            case PropertyType.PtypMultipleString:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVszW.Values);
                offset += sizeof(uint);
                IntPtr lppszW = Marshal.AllocHGlobal((int)(propertyValue.Value.MVszW.Values * 4));
                for (int i = 0; i < propertyValue.Value.MVszW.Values; i++)
                {
                    Marshal.WriteInt32(lppszW, 4 * i, Marshal.StringToHGlobalUni(propertyValue.Value.MVszW.LppszW[i]).ToInt32());
                }

                Marshal.WriteInt32(ptr, offset, lppszW.ToInt32());
                break;
            }

            case PropertyType.PtypMultipleGuid:
            {
                Marshal.WriteInt32(ptr, offset, (int)propertyValue.Value.MVguid.Values);
                offset += sizeof(uint);
                IntPtr lpguid = Marshal.AllocHGlobal((int)(propertyValue.Value.MVguid.Values * 4));
                for (int i = 0; i < propertyValue.Value.MVguid.Values; i++)
                {
                    IntPtr guid = Marshal.AllocHGlobal(16);
                    for (int j = 0; j < 16; j++)
                    {
                        Marshal.WriteByte(guid, j, propertyValue.Value.MVguid.Guid[i].Ab[j]);
                    }

                    Marshal.WriteInt32(lpguid, 4 * i, guid.ToInt32());
                }

                Marshal.WriteInt32(ptr, offset, lpguid.ToInt32());
                break;
            }

            case PropertyType.PtypNull:
            case PropertyType.PtypEmbeddedTable:
            {
                Marshal.WriteInt32(ptr, offset, propertyValue.Value.Reserved);
                break;
            }
            }

            return(ptr);
        }