Example #1
0
        public void WriteMarshalInfo(MarshalInfo marshal_info)
        {
            this.WriteNativeType(marshal_info.native);
            NativeType native = marshal_info.native;

            if (native == NativeType.FixedSysString)
            {
                FixedSysStringMarshalInfo fixedSysStringMarshalInfo = (FixedSysStringMarshalInfo)marshal_info;
                if (fixedSysStringMarshalInfo.size > -1)
                {
                    base.WriteCompressedUInt32((uint)fixedSysStringMarshalInfo.size);
                }
                return;
            }
            switch (native)
            {
            case NativeType.SafeArray:
            {
                SafeArrayMarshalInfo safeArrayMarshalInfo = (SafeArrayMarshalInfo)marshal_info;
                if (safeArrayMarshalInfo.element_type != VariantType.None)
                {
                    this.WriteVariantType(safeArrayMarshalInfo.element_type);
                }
                return;
            }

            case NativeType.FixedArray:
            {
                FixedArrayMarshalInfo fixedArrayMarshalInfo = (FixedArrayMarshalInfo)marshal_info;
                if (fixedArrayMarshalInfo.size > -1)
                {
                    base.WriteCompressedUInt32((uint)fixedArrayMarshalInfo.size);
                }
                if (fixedArrayMarshalInfo.element_type != NativeType.None)
                {
                    this.WriteNativeType(fixedArrayMarshalInfo.element_type);
                }
                return;
            }

            default:
                switch (native)
                {
                case NativeType.Array:
                {
                    ArrayMarshalInfo arrayMarshalInfo = (ArrayMarshalInfo)marshal_info;
                    if (arrayMarshalInfo.element_type != NativeType.None)
                    {
                        this.WriteNativeType(arrayMarshalInfo.element_type);
                    }
                    if (arrayMarshalInfo.size_parameter_index > -1)
                    {
                        base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_index);
                    }
                    if (arrayMarshalInfo.size > -1)
                    {
                        base.WriteCompressedUInt32((uint)arrayMarshalInfo.size);
                    }
                    if (arrayMarshalInfo.size_parameter_multiplier > -1)
                    {
                        base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_multiplier);
                    }
                    return;
                }

                case NativeType.LPStruct:
                    break;

                case NativeType.CustomMarshaler:
                {
                    CustomMarshalInfo customMarshalInfo = (CustomMarshalInfo)marshal_info;
                    this.WriteUTF8String((customMarshalInfo.guid != Guid.Empty) ? customMarshalInfo.guid.ToString() : string.Empty);
                    this.WriteUTF8String(customMarshalInfo.unmanaged_type);
                    this.WriteTypeReference(customMarshalInfo.managed_type);
                    this.WriteUTF8String(customMarshalInfo.cookie);
                    break;
                }

                default:
                    return;
                }
                return;
            }
        }
Example #2
0
        public MarshalInfo ReadMarshalInfo()
        {
            NativeType nativeType  = this.ReadNativeType();
            NativeType nativeType2 = nativeType;

            if (nativeType2 == NativeType.FixedSysString)
            {
                FixedSysStringMarshalInfo fixedSysStringMarshalInfo = new FixedSysStringMarshalInfo();
                if (this.CanReadMore())
                {
                    fixedSysStringMarshalInfo.size = (int)base.ReadCompressedUInt32();
                }
                return(fixedSysStringMarshalInfo);
            }
            switch (nativeType2)
            {
            case NativeType.SafeArray:
            {
                SafeArrayMarshalInfo safeArrayMarshalInfo = new SafeArrayMarshalInfo();
                if (this.CanReadMore())
                {
                    safeArrayMarshalInfo.element_type = this.ReadVariantType();
                }
                return(safeArrayMarshalInfo);
            }

            case NativeType.FixedArray:
            {
                FixedArrayMarshalInfo fixedArrayMarshalInfo = new FixedArrayMarshalInfo();
                if (this.CanReadMore())
                {
                    fixedArrayMarshalInfo.size = (int)base.ReadCompressedUInt32();
                }
                if (this.CanReadMore())
                {
                    fixedArrayMarshalInfo.element_type = this.ReadNativeType();
                }
                return(fixedArrayMarshalInfo);
            }

            default:
                switch (nativeType2)
                {
                case NativeType.Array:
                {
                    ArrayMarshalInfo arrayMarshalInfo = new ArrayMarshalInfo();
                    if (this.CanReadMore())
                    {
                        arrayMarshalInfo.element_type = this.ReadNativeType();
                    }
                    if (this.CanReadMore())
                    {
                        arrayMarshalInfo.size_parameter_index = (int)base.ReadCompressedUInt32();
                    }
                    if (this.CanReadMore())
                    {
                        arrayMarshalInfo.size = (int)base.ReadCompressedUInt32();
                    }
                    if (this.CanReadMore())
                    {
                        arrayMarshalInfo.size_parameter_multiplier = (int)base.ReadCompressedUInt32();
                    }
                    return(arrayMarshalInfo);
                }

                case NativeType.CustomMarshaler:
                {
                    CustomMarshalInfo customMarshalInfo = new CustomMarshalInfo();
                    string            text = this.ReadUTF8String();
                    customMarshalInfo.guid           = ((!string.IsNullOrEmpty(text)) ? new Guid(text) : Guid.Empty);
                    customMarshalInfo.unmanaged_type = this.ReadUTF8String();
                    customMarshalInfo.managed_type   = this.ReadTypeReference();
                    customMarshalInfo.cookie         = this.ReadUTF8String();
                    return(customMarshalInfo);
                }
                }
                return(new MarshalInfo(nativeType));
            }
        }