private UnmanagedMarshal(UnmanagedType unmanagedType, Guid guid, int numElem, UnmanagedType type)
 {
     this.m_unmanagedType = unmanagedType;
     this.m_guid = guid;
     this.m_numElem = numElem;
     this.m_baseType = type;
 }
Exemplo n.º 2
0
 public AudioDevice(int deviceNum)
 {
     this.deviceNum = deviceNum;
     this.deviceID = GetDeviceID(this.deviceNum);
     this.deviceUnmanagedID = GetUnmanagedDeviceID(this.deviceNum);
     this.deviceName = GetDeviceFriendlyName(this.deviceNum);
 }
 public static UnmanagedMarshal DefineUnmanagedMarshal(UnmanagedType unmanagedType)
 {
     if (((unmanagedType == UnmanagedType.ByValTStr) || (unmanagedType == UnmanagedType.SafeArray)) || (((unmanagedType == UnmanagedType.CustomMarshaler) || (unmanagedType == UnmanagedType.ByValArray)) || (unmanagedType == UnmanagedType.LPArray)))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NotASimpleNativeType"));
     }
     return new UnmanagedMarshal(unmanagedType, Guid.Empty, 0, (UnmanagedType) 0);
 }
Exemplo n.º 4
0
	public static int Main ()
	{
		UnmanagedType = (UnmanagedType) 0;

		if (UnmanagedType != 0)
			return 1;

		return 0;
	}
Exemplo n.º 5
0
        private static CustomAttributeBuilder GetMarshalAsAttribute(UnmanagedType unmanagedType)
        {
            Type[] ctorParams = new Type[] { typeof(UnmanagedType) };
            ConstructorInfo classCtorInfo = typeof(MarshalAsAttribute).GetConstructor(ctorParams);

            CustomAttributeBuilder builder = new CustomAttributeBuilder(
                                classCtorInfo,
                                new object[] { unmanagedType });
            return builder;
        }
Exemplo n.º 6
0
 internal static void GetMarshalAs(ConstArray nativeType, out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
 {
     int num;
     int num2;
     int num3;
     _GetMarshalAs(nativeType.Signature, nativeType.Length, out num, out num2, out safeArrayUserDefinedSubType, out num3, out sizeParamIndex, out sizeConst, out marshalType, out marshalCookie, out iidParamIndex);
     unmanagedType = (UnmanagedType) num;
     safeArraySubType = (VarEnum) num2;
     arraySubType = (UnmanagedType) num3;
 }
Exemplo n.º 7
0
        /******************************
[System.Runtime.InteropServices.ComVisible(true)]
        * public static constructors. You can only construct
        * UnmanagedMarshal using these static constructors. 
        ******************************/
        public static UnmanagedMarshal DefineUnmanagedMarshal(UnmanagedType unmanagedType) 
        { 
            if (unmanagedType == UnmanagedType.ByValTStr ||
#if FEATURE_COMINTEROP 
                unmanagedType == UnmanagedType.SafeArray ||
                unmanagedType == UnmanagedType.CustomMarshaler ||
#endif //FEATURE_COMINTEROP
                unmanagedType == UnmanagedType.ByValArray || 
                unmanagedType == UnmanagedType.LPArray)
            { 
                // not a simple native marshal 
                throw new ArgumentException(Environment.GetResourceString("Argument_NotASimpleNativeType"));
            } 
            return new UnmanagedMarshal(unmanagedType, Guid.Empty, 0, (UnmanagedType) 0);
        }
Exemplo n.º 8
0
    private int Verify(UnmanagedType umt, int expectedValue)
    {
        Console.WriteLine("Verify " + umt);
        try
        {
            if (expectedValue == (int)umt)
                return 0;

            Console.WriteLine("Error! Actual: {0}, Expected: {1}", (int)umt, expectedValue);
        }
        catch (Exception e)
        {
            Console.WriteLine("UnexpectedEception: " + e);
        }
        return 1;
    }
Exemplo n.º 9
0
 public MarshalAsAttribute(UnmanagedType unmanagedType)
 {
     _val = unmanagedType;
 }
Exemplo n.º 10
0
 public void SetMarshalAsParameter(int index, UnmanagedType umt)
 {
     _marshalAsIndex[index]  = true;
     _marshalAsBuffer[index] = umt;
 }
	private UnmanagedMarshal(UnmanagedType type, UnmanagedType baseType)
			{
				this.type = type;
				this.elemCount = elemCount;
			}
Exemplo n.º 12
0
 public static UnmanagedMarshal DefineSafeArray(UnmanagedType elemType)
 {
     return new UnmanagedMarshal(UnmanagedType.SafeArray, Guid.Empty, 0, elemType);
 }
Exemplo n.º 13
0
 public static CustomAttributeBuilder GetBuilderForMarshalAsConstArray(UnmanagedType unmanagedType, int length, UnmanagedType arraySubType)
 {
     ConstructorInfo ctorMarshalAs = typeof(MarshalAsAttribute).GetConstructor(new Type[] { typeof(UnmanagedType) });
     FieldInfo fieldSizeConst = typeof(MarshalAsAttribute).GetField("SizeConst");
     FieldInfo fieldArraySubType = typeof(MarshalAsAttribute).GetField("ArraySubType");
     return new CustomAttributeBuilder(
         ctorMarshalAs,
         new Object[] { unmanagedType },
         new FieldInfo[] { fieldSizeConst, fieldArraySubType },
         new Object[] { length, arraySubType }
         );
 }
 internal void SetMarshalAsSimpleType(UnmanagedType type)
 {
     Debug.Assert(type >= 0 && (int)type <= MaxMarshalInteger);
     _marshalType = type;
 }
Exemplo n.º 15
0
 public static UnmanagedMarshal DefineUnmanagedMarshal(UnmanagedType unmanagedType) => throw new PlatformNotSupportedException();
Exemplo n.º 16
0
 public static UnmanagedMarshal DefineLPArray(UnmanagedType elemType) => throw new PlatformNotSupportedException();
Exemplo n.º 17
0
 static extern Int32 SetDefaultAudioPlaybackDevice(UnmanagedType deviceID);
Exemplo n.º 18
0
            private static CharSet? MarshalingToCharSet(UnmanagedType? type)
            {
                if (type == null)
                {
                    return null;
                }

                switch (type)
                {
                    case UnmanagedType.AnsiBStr:
                    case UnmanagedType.LPStr:
                    case UnmanagedType.VBByRefStr:
                        return CharSet.Ansi;
                    case UnmanagedType.BStr:
                    case UnmanagedType.LPWStr:
                        return CharSet.Unicode;
                    case UnmanagedType.ByValTStr:
                    case UnmanagedType.LPTStr:
                    case UnmanagedType.TBStr:
                        return CharSet.Auto;
                    default:
                        return CharSet.None;
                }
            }
	private UnmanagedMarshal(UnmanagedType type, int elemCount)
			{
				this.type = type;
				this.elemCount = elemCount;
			}
Exemplo n.º 20
0
 public static TypeName GetTypeNameForUnmanagedType(UnmanagedType unmngType)
 {
     return primitiveUnmanagedToNameMap[(int)unmngType];
 }
Exemplo n.º 21
0
        /// <summary>
        /// Emits the IL instructions neccesary to convert an unmanaged integer value on the evaluation stack to its
        /// boolean representation.
        /// </summary>
        /// <param name="il">The generator where the IL is to be emitted.</param>
        /// <param name="unmanagedType">The unmanaged type of the boolean.</param>
        private void EmitUnmanagedIntegerToBooleanConversion([NotNull] ILGenerator il, UnmanagedType unmanagedType)
        {
            var trueCase       = il.DefineLabel();
            var endOfCondition = il.DefineLabel();

            // Convert whatever's on the stack to a long
            il.EmitConvertToLong();

            // Push the value for true onto the stack
            il.EmitConstantLong(GetBooleanIntegerValueForUnmanagedType(unmanagedType, true));
            il.EmitBranchIfEqual(trueCase);

            // false case
            il.EmitConstantInt(0);
            il.EmitBranch(endOfCondition);

            // true case
            il.MarkLabel(trueCase);
            il.EmitConstantInt(1);

            il.MarkLabel(endOfCondition);
        }
Exemplo n.º 22
0
        private static int WriteMarshallingDescriptor(ModuleBuilder module, CustomAttributeBuilder attribute)
        {
            UnmanagedType unmanagedType;
            object        val = attribute.GetConstructorArgument(0);

            if (val is short)
            {
                unmanagedType = (UnmanagedType)(short)val;
            }
            else if (val is int)
            {
                unmanagedType = (UnmanagedType)(int)val;
            }
            else
            {
                unmanagedType = (UnmanagedType)val;
            }

            ByteBuffer bb = new ByteBuffer(5);

            bb.WriteCompressedInt((int)unmanagedType);

            if (unmanagedType == UnmanagedType.LPArray)
            {
                UnmanagedType arraySubType = attribute.GetFieldValue <UnmanagedType>("ArraySubType") ?? NATIVE_TYPE_MAX;
                bb.WriteCompressedInt((int)arraySubType);
                int?sizeParamIndex = attribute.GetFieldValue <short>("SizeParamIndex");
                int?sizeConst      = attribute.GetFieldValue <int>("SizeConst");
                if (sizeParamIndex != null)
                {
                    bb.WriteCompressedInt(sizeParamIndex.Value);
                    if (sizeConst != null)
                    {
                        bb.WriteCompressedInt(sizeConst.Value);
                        bb.WriteCompressedInt(1);                         // flag that says that SizeParamIndex was specified
                    }
                }
                else if (sizeConst != null)
                {
                    bb.WriteCompressedInt(0);                     // SizeParamIndex
                    bb.WriteCompressedInt(sizeConst.Value);
                    bb.WriteCompressedInt(0);                     // flag that says that SizeParamIndex was not specified
                }
            }
            else if (unmanagedType == UnmanagedType.SafeArray)
            {
                VarEnum?safeArraySubType = attribute.GetFieldValue <VarEnum>("SafeArraySubType");
                if (safeArraySubType != null)
                {
                    bb.WriteCompressedInt((int)safeArraySubType);
                    Type safeArrayUserDefinedSubType = (Type)attribute.GetFieldValue("SafeArrayUserDefinedSubType");
                    if (safeArrayUserDefinedSubType != null)
                    {
                        WriteType(module, bb, safeArrayUserDefinedSubType);
                    }
                }
            }
            else if (unmanagedType == UnmanagedType.ByValArray)
            {
                bb.WriteCompressedInt(attribute.GetFieldValue <int>("SizeConst") ?? 1);
                UnmanagedType?arraySubType = attribute.GetFieldValue <UnmanagedType>("ArraySubType");
                if (arraySubType != null)
                {
                    bb.WriteCompressedInt((int)arraySubType);
                }
            }
            else if (unmanagedType == UnmanagedType.ByValTStr)
            {
                bb.WriteCompressedInt(attribute.GetFieldValue <int>("SizeConst").Value);
            }
            else if (unmanagedType == UnmanagedType.Interface ||
                     unmanagedType == UnmanagedType.IDispatch ||
                     unmanagedType == UnmanagedType.IUnknown)
            {
                int?iidParameterIndex = attribute.GetFieldValue <int>("IidParameterIndex");
                if (iidParameterIndex != null)
                {
                    bb.WriteCompressedInt(iidParameterIndex.Value);
                }
            }
            else if (unmanagedType == UnmanagedType.CustomMarshaler)
            {
                bb.WriteCompressedInt(0);
                bb.WriteCompressedInt(0);
                string marshalType = (string)attribute.GetFieldValue("MarshalType");
                if (marshalType != null)
                {
                    WriteString(bb, marshalType);
                }
                else
                {
                    WriteType(module, bb, (Type)attribute.GetFieldValue("MarshalTypeRef"));
                }
                WriteString(bb, (string)attribute.GetFieldValue("MarshalCookie") ?? "");
            }

            return(module.Blobs.Add(bb));
        }
	// Constructor.
	private UnmanagedMarshal(UnmanagedType type)
			{
				this.type = type;
			}
Exemplo n.º 24
0
        internal static CustomAttributeData GetMarshalAsAttribute(Module module, int token)
        {
            // TODO use binary search?
            for (int i = 0; i < module.FieldMarshal.records.Length; i++)
            {
                if (module.FieldMarshal.records[i].Parent == token)
                {
                    ByteReader    blob                        = module.GetBlob(module.FieldMarshal.records[i].NativeType);
                    UnmanagedType unmanagedType               = (UnmanagedType)blob.ReadCompressedInt();
                    UnmanagedType?arraySubType                = null;
                    short?        sizeParamIndex              = null;
                    int?          sizeConst                   = null;
                    VarEnum?      safeArraySubType            = null;
                    Type          safeArrayUserDefinedSubType = null;
                    int?          iidParameterIndex           = null;
                    string        marshalType                 = null;
                    string        marshalCookie               = null;
                    Type          marshalTypeRef              = null;
                    if (unmanagedType == UnmanagedType.LPArray)
                    {
                        arraySubType = (UnmanagedType)blob.ReadCompressedInt();
                        if (arraySubType == NATIVE_TYPE_MAX)
                        {
                            arraySubType = null;
                        }
                        if (blob.Length != 0)
                        {
                            sizeParamIndex = (short)blob.ReadCompressedInt();
                            if (blob.Length != 0)
                            {
                                sizeConst = blob.ReadCompressedInt();
                                if (blob.Length != 0 && blob.ReadCompressedInt() == 0)
                                {
                                    sizeParamIndex = null;
                                }
                            }
                        }
                    }
                    else if (unmanagedType == UnmanagedType.SafeArray)
                    {
                        if (blob.Length != 0)
                        {
                            safeArraySubType = (VarEnum)blob.ReadCompressedInt();
                            if (blob.Length != 0)
                            {
                                safeArrayUserDefinedSubType = ReadType(module, blob);
                            }
                        }
                    }
                    else if (unmanagedType == UnmanagedType.ByValArray)
                    {
                        sizeConst = blob.ReadCompressedInt();
                        if (blob.Length != 0)
                        {
                            arraySubType = (UnmanagedType)blob.ReadCompressedInt();
                        }
                    }
                    else if (unmanagedType == UnmanagedType.ByValTStr)
                    {
                        sizeConst = blob.ReadCompressedInt();
                    }
                    else if (unmanagedType == UnmanagedType.Interface ||
                             unmanagedType == UnmanagedType.IDispatch ||
                             unmanagedType == UnmanagedType.IUnknown)
                    {
                        if (blob.Length != 0)
                        {
                            iidParameterIndex = blob.ReadCompressedInt();
                        }
                    }
                    else if (unmanagedType == UnmanagedType.CustomMarshaler)
                    {
                        blob.ReadCompressedInt();
                        blob.ReadCompressedInt();
                        marshalType    = ReadString(blob);
                        marshalCookie  = ReadString(blob);
                        marshalTypeRef = module.Assembly.GetType(marshalType) ?? module.universe.GetType(marshalType);
                    }

                    Type typeofMarshalAs     = module.universe.System_Runtime_InteropServices_MarshalAsAttribute;
                    Type typeofUnmanagedType = module.universe.System_Runtime_InteropServices_UnmanagedType;
                    Type typeofVarEnum       = module.universe.System_Runtime_InteropServices_VarEnum;
                    Type typeofType          = module.universe.System_Type;
                    List <CustomAttributeNamedArgument> named = new List <CustomAttributeNamedArgument>();
                    if (arraySubType != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("ArraySubType"), new CustomAttributeTypedArgument(typeofUnmanagedType, arraySubType.Value)));
                    }
                    if (sizeParamIndex != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("SizeParamIndex"), new CustomAttributeTypedArgument(module.universe.System_Int16, sizeParamIndex.Value)));
                    }
                    if (sizeConst != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("SizeConst"), new CustomAttributeTypedArgument(module.universe.System_Int32, sizeConst.Value)));
                    }
                    if (safeArraySubType != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("SafeArraySubType"), new CustomAttributeTypedArgument(typeofVarEnum, safeArraySubType.Value)));
                    }
                    if (safeArrayUserDefinedSubType != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("SafeArrayUserDefinedSubType"), new CustomAttributeTypedArgument(typeofType, safeArrayUserDefinedSubType)));
                    }
                    if (iidParameterIndex != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("IidParameterIndex"), new CustomAttributeTypedArgument(module.universe.System_Int32, iidParameterIndex.Value)));
                    }
                    if (marshalType != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("MarshalType"), new CustomAttributeTypedArgument(module.universe.System_String, marshalType)));
                    }
                    if (marshalTypeRef != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("MarshalTypeRef"), new CustomAttributeTypedArgument(module.universe.System_Type, marshalTypeRef)));
                    }
                    if (marshalCookie != null)
                    {
                        named.Add(new CustomAttributeNamedArgument(typeofMarshalAs.GetField("MarshalCookie"), new CustomAttributeTypedArgument(module.universe.System_String, marshalCookie)));
                    }
                    ConstructorInfo constructor = typeofMarshalAs.GetConstructor(new Type[] { typeofUnmanagedType });
                    return(new CustomAttributeData(constructor, new object[] { unmanagedType }, named));
                }
            }
            throw new BadImageFormatException();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Get the corresponding <see cref="NativeType"/> for a specific <see cref="UnmanagedType"/>.
        /// </summary>
        /// <param name="unmanagedType">The unmanaged type to convert.</param>
        /// <returns></returns>
        private static NativeType GetNativeType(UnmanagedType unmanagedType)
        {
            switch (unmanagedType)
            {
            case UnmanagedType.AnsiBStr:
                return(NativeType.ANSIBStr);

            case UnmanagedType.AsAny:
                return(NativeType.ASAny);

            case UnmanagedType.Bool:
                return(NativeType.Boolean);

            case UnmanagedType.BStr:
                return(NativeType.BStr);

            case UnmanagedType.ByValArray:
                return(NativeType.FixedArray);

            case UnmanagedType.ByValTStr:
                return(NativeType.ByValStr);

            case UnmanagedType.Currency:
                return(NativeType.Currency);

            case UnmanagedType.CustomMarshaler:
                return(NativeType.CustomMarshaler);

            case UnmanagedType.Error:
                return(NativeType.Error);

            case UnmanagedType.FunctionPtr:
                return(NativeType.Func);

            case UnmanagedType.I1:
                return(NativeType.I1);

            case UnmanagedType.I2:
                return(NativeType.I2);

            case UnmanagedType.I4:
                return(NativeType.I4);

            case UnmanagedType.I8:
                return(NativeType.I8);

            case UnmanagedType.IDispatch:
                return(NativeType.IDispatch);

            case UnmanagedType.LPArray:
                return(NativeType.Array);

            case UnmanagedType.LPStr:
                return(NativeType.LPStr);

            case UnmanagedType.LPStruct:
                return(NativeType.LPStruct);

            case UnmanagedType.LPTStr:
                return(NativeType.LPTStr);

            case UnmanagedType.LPWStr:
                return(NativeType.LPWStr);

            case UnmanagedType.R4:
                return(NativeType.R4);

            case UnmanagedType.R8:
                return(NativeType.R8);

            case UnmanagedType.SafeArray:
                return(NativeType.SafeArray);

            case UnmanagedType.Struct:
                return(NativeType.Struct);

            case UnmanagedType.SysInt:
                return(NativeType.Int);

            case UnmanagedType.SysUInt:
                return(NativeType.UInt);

            case UnmanagedType.TBStr:
                return(NativeType.TBStr);

            case UnmanagedType.U1:
                return(NativeType.U1);

            case UnmanagedType.U2:
                return(NativeType.U2);

            case UnmanagedType.U4:
                return(NativeType.U4);

            case UnmanagedType.U8:
                return(NativeType.U8);

            case UnmanagedType.VariantBool:
                return(NativeType.VariantBool);

            case UnmanagedType.HString:
            case UnmanagedType.IInspectable:
            case UnmanagedType.Interface:
            case UnmanagedType.IUnknown:
            case UnmanagedType.VBByRefStr:
                throw new ArgumentException(nameof(unmanagedType), $"Marshal type \"{unmanagedType}\" is not supported.");

            default:
                throw new ArgumentOutOfRangeException(nameof(unmanagedType), unmanagedType, null);
            }
        }
Exemplo n.º 26
0
 // Constructor.
 private UnmanagedMarshal(UnmanagedType type)
 {
     this.type = type;
 }
Exemplo n.º 27
0
		public static UnmanagedMarshal DefineUnmanagedMarshal( UnmanagedType unmanagedType) {
			return new UnmanagedMarshal (unmanagedType, unmanagedType);
		}
Exemplo n.º 28
0
 private UnmanagedMarshal(UnmanagedType type, int elemCount)
 {
     this.type      = type;
     this.elemCount = elemCount;
 }
Exemplo n.º 29
0
 public MarshalAsAttribute(UnmanagedType unmanagedType)
 {
 }
Exemplo n.º 30
0
 private UnmanagedMarshal(UnmanagedType type, UnmanagedType baseType)
 {
     this.type      = type;
     this.elemCount = elemCount;
 }
 public MarshalAsAttribute(UnmanagedType unmanagedType)
 {
     utype = unmanagedType;
 }
Exemplo n.º 32
0
 public StructuringAttribute(UnmanagedType unmanaged)
 {
     Value = unmanaged;
 }
 internal PrimitiveMarshalType(CodeNode parent, UnmanagedType unmanagedType)
     : base(parent)
 {
     _unmanagedType = unmanagedType;
 }
Exemplo n.º 34
0
 // the fields are not stored anywhere, they are to be accessed by SilkTouch via Roslyn
 public UnmanagedTypeAttribute(UnmanagedType unmanagedType)
 {
 }
Exemplo n.º 35
0
 public MarshalAsAttribute(short unmanagedType)
 {
     _val = (UnmanagedType)unmanagedType;
 }
        private static void DecodeMarshalAsComInterface(ref DecodeWellKnownAttributeArguments <TAttributeSyntax, TAttributeData, TAttributeLocation> arguments, UnmanagedType unmanagedType, CommonMessageProvider messageProvider)
        {
            Debug.Assert((object)arguments.AttributeSyntaxOpt != null);

            int? parameterIndex = null;
            int  position       = 1;
            bool hasErrors      = false;

            foreach (var namedArg in arguments.Attribute.NamedArguments)
            {
                switch (namedArg.Key)
                {
                case "IidParameterIndex":
                    parameterIndex = namedArg.Value.DecodeValue <int>(SpecialType.System_Int32);
                    if (parameterIndex < 0 || parameterIndex > MarshalPseudoCustomAttributeData.MaxMarshalInteger)
                    {
                        messageProvider.ReportInvalidNamedArgument(arguments.Diagnostics, arguments.AttributeSyntaxOpt, position, arguments.Attribute.AttributeClass, namedArg.Key);
                        hasErrors = true;
                    }

                    break;

                    // other parameters ignored with no error
                }

                position++;
            }

            if (!hasErrors)
            {
                arguments.GetOrCreateData <TWellKnownAttributeData>().GetOrCreateData().SetMarshalAsComInterface(unmanagedType, parameterIndex);
            }
        }
Exemplo n.º 37
0
        /// <summary>
        /// Emits the IL instructions neccesary to convert a boolean value on the evaluation stack to its unmanaged
        /// integer representation.
        /// </summary>
        /// <param name="il">The generator where the IL is to be emitted.</param>
        /// <param name="unmanagedType">The unmanaged type of the boolean.</param>
        private void EmitBooleanToUnmanagedIntegerConversion([NotNull] ILGenerator il, UnmanagedType unmanagedType)
        {
            var trueCase       = il.DefineLabel();
            var endOfCondition = il.DefineLabel();

            il.EmitBranchTrue(trueCase);

            // false case
            if (unmanagedType == U8 || unmanagedType == I8)
            {
                il.EmitConstantLong(GetBooleanIntegerValueForUnmanagedType(unmanagedType, false));
            }
            else
            {
                il.EmitConstantInt((int)GetBooleanIntegerValueForUnmanagedType(unmanagedType, false));
            }

            il.EmitBranch(endOfCondition);

            // true case
            il.MarkLabel(trueCase);
            if (unmanagedType == U8 || unmanagedType == I8)
            {
                il.EmitConstantLong(GetBooleanIntegerValueForUnmanagedType(unmanagedType, true));
            }
            else
            {
                il.EmitConstantInt((int)GetBooleanIntegerValueForUnmanagedType(unmanagedType, true));
            }

            il.MarkLabel(endOfCondition);
        }
Exemplo n.º 38
0
        internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuilder, bool is_field)
        {
            byte[]        data           = customBuilder.Data;
            UnmanagedType subtype        = (UnmanagedType)0x50; /* NATIVE_MAX */
            int           sizeConst      = -1;
            int           sizeParamIndex = -1;
            bool          hasSize        = false;
            int           value;
            int           utype; /* the (stupid) ctor takes a short or an enum ... */
            string?       marshalTypeName = null;
            Type?         marshalTypeRef  = null;
            string        marshalCookie   = string.Empty;

            utype  = (int)data[2];
            utype |= ((int)data[3]) << 8;

            string?first_type_name = GetParameters(customBuilder.Ctor)[0].ParameterType.FullName;
            int    pos             = 6;

            if (first_type_name == "System.Int16")
            {
                pos = 4;
            }
            int nnamed = (int)data[pos++];

            nnamed |= ((int)data[pos++]) << 8;

            for (int i = 0; i < nnamed; ++i)
            {
                int paramType; // What is this ?

                /* Skip field/property signature */
                int fieldPropSig = (int)data[pos++];
                /* Read type */
                paramType = ((int)data[pos++]);
                if (paramType == 0x55)
                {
                    /* enums, the value is preceeded by the type */
                    decode_string(data, pos, out pos);
                }
                string?named_name = decode_string(data, pos, out pos);

                switch (named_name)
                {
                case "ArraySubType":
                    value   = (int)data[pos++];
                    value  |= ((int)data[pos++]) << 8;
                    value  |= ((int)data[pos++]) << 16;
                    value  |= ((int)data[pos++]) << 24;
                    subtype = (UnmanagedType)value;
                    break;

                case "SizeConst":
                    value     = (int)data[pos++];
                    value    |= ((int)data[pos++]) << 8;
                    value    |= ((int)data[pos++]) << 16;
                    value    |= ((int)data[pos++]) << 24;
                    sizeConst = value;
                    hasSize   = true;
                    break;

                case "SafeArraySubType":
                    value   = (int)data[pos++];
                    value  |= ((int)data[pos++]) << 8;
                    value  |= ((int)data[pos++]) << 16;
                    value  |= ((int)data[pos++]) << 24;
                    subtype = (UnmanagedType)value;
                    break;

                case "IidParameterIndex":
                    pos += 4;
                    break;

                case "SafeArrayUserDefinedSubType":
                    decode_string(data, pos, out pos);
                    break;

                case "SizeParamIndex":
                    value          = (int)data[pos++];
                    value         |= ((int)data[pos++]) << 8;
                    sizeParamIndex = value;
                    hasSize        = true;
                    break;

                case "MarshalType":
                    marshalTypeName = decode_string(data, pos, out pos);
                    break;

                case "MarshalTypeRef":
                    marshalTypeName = decode_string(data, pos, out pos);
                    if (marshalTypeName != null)
                    {
                        marshalTypeRef = Type.GetType(marshalTypeName);
                    }
                    break;

                case "MarshalCookie":
                    marshalCookie = decode_string(data, pos, out pos) !;
                    break;

                default:
                    throw new Exception("Unknown MarshalAsAttribute field: " + named_name);
                }
            }

            switch ((UnmanagedType)utype)
            {
            case UnmanagedType.LPArray:
                if (hasSize)
                {
                    return(UnmanagedMarshal.DefineLPArrayInternal(subtype, sizeConst, sizeParamIndex));
                }
                else
                {
                    return(UnmanagedMarshal.DefineLPArray(subtype));
                }

#if FEATURE_COMINTEROP
            case UnmanagedType.SafeArray:
                return(UnmanagedMarshal.DefineSafeArray(subtype));
#endif
            case UnmanagedType.ByValArray:
                if (!is_field)
                {
                    throw new ArgumentException("Specified unmanaged type is only valid on fields");
                }

                return(UnmanagedMarshal.DefineByValArray(sizeConst));

            case UnmanagedType.ByValTStr:
                return(UnmanagedMarshal.DefineByValTStr(sizeConst));

#if FEATURE_COMINTEROP
            case UnmanagedType.CustomMarshaler:
                return(UnmanagedMarshal.DefineCustom(marshalTypeRef, marshalCookie, marshalTypeName, Guid.Empty));
#endif
            default:
                return(UnmanagedMarshal.DefineUnmanagedMarshal((UnmanagedType)utype));
            }
        }
 internal void SetMarshalAsCustom(object typeSymbolOrName, string cookie)
 {
     _marshalType             = Cci.Constants.UnmanagedType_CustomMarshaler;
     _marshalTypeNameOrSymbol = typeSymbolOrName;
     _marshalCookie           = cookie;
 }
Exemplo n.º 40
0
 private CustomAttributeBuilder CreateMarshalAsAttribute(UnmanagedType unmanagedType)
 {
     return(new CustomAttributeBuilder(typeof(MarshalAsAttribute).GetConstructor(new Type[] { typeof(UnmanagedType) }), new object[] { unmanagedType }));
 }
Exemplo n.º 41
0
 public static UnmanagedMarshal DefineSafeArray(UnmanagedType elemType)
 {
     return(new UnmanagedMarshal(UnmanagedType.SafeArray, elemType));
 }
        public MarshalType CreateMarshalType(UnmanagedType type)
        {
            MarshalType = MarshalType.CreateNew(this, type);

            return(_marshalType);
        }
Exemplo n.º 43
0
 public static CustomAttributeBuilder GetBuilderForMarshalAs(UnmanagedType unmanagedType)
 {
     ConstructorInfo ctorMarshalAs = typeof(MarshalAsAttribute).GetConstructor(new Type[] { typeof(UnmanagedType) });
     return new CustomAttributeBuilder(ctorMarshalAs, new Object[] { unmanagedType });
 }
Exemplo n.º 44
0
 internal MarshalAsAttribute(UnmanagedType val, VarEnum safeArraySubType, RuntimeType safeArrayUserDefinedSubType, UnmanagedType arraySubType,
                             short sizeParamIndex, int sizeConst, string marshalType, RuntimeType marshalTypeRef, string marshalCookie, int iidParamIndex)
 {
     _val                        = val;
     SafeArraySubType            = safeArraySubType;
     SafeArrayUserDefinedSubType = safeArrayUserDefinedSubType;
     IidParameterIndex           = iidParamIndex;
     ArraySubType                = arraySubType;
     SizeParamIndex              = sizeParamIndex;
     SizeConst                   = sizeConst;
     MarshalType                 = marshalType;
     MarshalTypeRef              = marshalTypeRef;
     MarshalCookie               = marshalCookie;
 }
Exemplo n.º 45
0
 public static CustomAttributeBuilder GetBuilderForMarshalAsConstArrayBySizeParamIndex(
     UnmanagedType unmanagedType, short sizeParamIndex)
 {
     ConstructorInfo ctorMarshalAs = typeof(MarshalAsAttribute).GetConstructor(new Type[] { typeof(UnmanagedType) });
     FieldInfo fieldSizeParamIndex = typeof(MarshalAsAttribute).GetField("SizeParamIndex");
     return new CustomAttributeBuilder(
         ctorMarshalAs,
         new Object[] { unmanagedType },
         new FieldInfo[] { fieldSizeParamIndex },
         new Object[] { sizeParamIndex }
         );
 }
Exemplo n.º 46
0
#pragma warning restore 169, 414
		
		private UnmanagedMarshal (UnmanagedType maint, int cnt) {
			count = cnt;
			t = maint;
			tbase = maint;
		}
Exemplo n.º 47
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void GetMarshalAs(ConstArray nativeType, 
            out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, 
            out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie,
            out int iidParamIndex)
        {
            int _unmanagedType, _safeArraySubType, _arraySubType;

            _GetMarshalAs(nativeType.Signature, (int)nativeType.Length,
                out _unmanagedType, out _safeArraySubType, out safeArrayUserDefinedSubType, 
                out _arraySubType, out sizeParamIndex, out sizeConst, out marshalType, out marshalCookie,
                out iidParamIndex);
            unmanagedType = (UnmanagedType)_unmanagedType;
            safeArraySubType = (VarEnum)_safeArraySubType;
            arraySubType = (UnmanagedType)_arraySubType;
        }
Exemplo n.º 48
0
		public static UnmanagedMarshal DefineLPArray( UnmanagedType elemType) {
			return new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
		}
Exemplo n.º 49
0
		public static Type GetUnmanagedType(UnmanagedType type)
		{
			switch (type)
			{
				case UnmanagedType.I1: return typeof(bool);
				case UnmanagedType.U1: return typeof(bool);
				case UnmanagedType.I2: return typeof(short);
				case UnmanagedType.I4: return typeof(int);
				case UnmanagedType.I8: return typeof(long);
				case UnmanagedType.R4: return typeof(float);
				case UnmanagedType.R8: return typeof(double);
				case UnmanagedType.Currency: return typeof(double);
				case UnmanagedType.ByValTStr: return typeof(char);
				default: throw new NotImplementedException();
			}
		}
Exemplo n.º 50
0
 internal MarshalAsAttribute(UnmanagedType val, VarEnum safeArraySubType, RuntimeType safeArrayUserDefinedSubType, UnmanagedType arraySubType,
     short sizeParamIndex, int sizeConst, string marshalType, RuntimeType marshalTypeRef, string marshalCookie, int iidParamIndex)
 {
     _val = val;
     SafeArraySubType = safeArraySubType;
     SafeArrayUserDefinedSubType = safeArrayUserDefinedSubType;
     IidParameterIndex = iidParamIndex;
     ArraySubType = arraySubType;
     SizeParamIndex = sizeParamIndex;
     SizeConst = sizeConst;
     MarshalType = marshalType;
     MarshalTypeRef = marshalTypeRef;
     MarshalCookie = marshalCookie;
 }
Exemplo n.º 51
0
		// sizeConst and sizeParamIndex can be -1 meaning they are not specified
		internal static UnmanagedMarshal DefineLPArrayInternal (UnmanagedType elemType, int sizeConst, int sizeParamIndex) {
			UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
			res.count = sizeConst;
			res.param_num = sizeParamIndex;
			res.has_size = true;

			return res;
		}
	// Define a simple unmanaged marshalling behaviour.
	public static UnmanagedMarshal DefineUnmanagedMarshal
				(UnmanagedType unmanagedType)
			{
				// Must be a simple unmanaged type.
				if(unmanagedType == UnmanagedType.ByValArray ||
				   unmanagedType == UnmanagedType.ByValTStr ||
				   unmanagedType == UnmanagedType.LPArray ||
				   unmanagedType == UnmanagedType.SafeArray ||
				   unmanagedType == UnmanagedType.CustomMarshaler)
				{
					throw new ArgumentException
						(_("Emit_NotSimpleUnmanagedType"));
				}
				return new UnmanagedMarshal(unmanagedType);
			}
Exemplo n.º 53
0
		private UnmanagedMarshal (UnmanagedType maint, UnmanagedType elemt) {
			count = 0;
			t = maint;
			tbase = elemt;
		}
Exemplo n.º 54
0
 public static UnmanagedMarshal DefineUnmanagedMarshal(UnmanagedType unmanagedType)
 {
     return(new UnmanagedMarshal(unmanagedType, unmanagedType));
 }
            private static CharSet? MarshalingToCharSet(UnmanagedType? type)
            {
                if (type == null)
                {
                    return null;
                }

                switch (type)
                {
                    case UnmanagedType.AnsiBStr:
                    case UnmanagedType.LPStr:
                    case UnmanagedType.VBByRefStr:
                        return CharSet.Ansi;
                    case UnmanagedType.BStr:
                    case UnmanagedType.LPWStr:
                        return CharSet.Unicode;
                    case UnmanagedType.ByValTStr:
                    case UnmanagedType.LPTStr:
                    case UnmanagedType.TBStr:
                    default:
                        // CharSet.Auto and CharSet.None are not available in the portable
                        // profiles. We are not interested in those values for our analysis and so simply
                        // return null
                        return null;
                }
            }
Exemplo n.º 56
0
 private UnmanagedMarshal(UnmanagedType maint, int cnt)
 {
     count = cnt;
     t     = maint;
     tbase = maint;
 }
Exemplo n.º 57
0
#pragma warning disable 169, 414

		public MarshalAsAttribute (short unmanagedType) {
			utype = (UnmanagedType)unmanagedType;
		}
Exemplo n.º 58
0
 private UnmanagedMarshal(UnmanagedType maint, UnmanagedType elemt)
 {
     count = 0;
     t     = maint;
     tbase = elemt;
 }
Exemplo n.º 59
0
 public void SetMarshalAsParameter(int index, UnmanagedType umt)
 {
     _marshalAsIndex[index] = true;
     _marshalAsBuffer[index] = umt;
 }
Exemplo n.º 60
0
        internal static void Decode(
            ref DecodeWellKnownAttributeArguments <
                TAttributeSyntax,
                TAttributeData,
                TAttributeLocation
                > arguments,
            AttributeTargets target,
            CommonMessageProvider messageProvider
            )
        {
            Debug.Assert((object)arguments.AttributeSyntaxOpt != null);

            UnmanagedType unmanagedType = DecodeMarshalAsType(arguments.Attribute);

            switch (unmanagedType)
            {
            case Cci.Constants.UnmanagedType_CustomMarshaler:
                DecodeMarshalAsCustom(ref arguments, messageProvider);
                break;

            case UnmanagedType.Interface:
            case Cci.Constants.UnmanagedType_IDispatch:
            case UnmanagedType.IUnknown:
                DecodeMarshalAsComInterface(ref arguments, unmanagedType, messageProvider);
                break;

            case UnmanagedType.LPArray:
                DecodeMarshalAsArray(ref arguments, messageProvider, isFixed: false);
                break;

            case UnmanagedType.ByValArray:
                if (target != AttributeTargets.Field)
                {
                    messageProvider.ReportMarshalUnmanagedTypeOnlyValidForFields(
                        arguments.Diagnostics,
                        arguments.AttributeSyntaxOpt,
                        0,
                        "ByValArray",
                        arguments.Attribute
                        );
                }
                else
                {
                    DecodeMarshalAsArray(ref arguments, messageProvider, isFixed: true);
                }
                break;

            case Cci.Constants.UnmanagedType_SafeArray:
                DecodeMarshalAsSafeArray(ref arguments, messageProvider);
                break;

            case UnmanagedType.ByValTStr:
                if (target != AttributeTargets.Field)
                {
                    messageProvider.ReportMarshalUnmanagedTypeOnlyValidForFields(
                        arguments.Diagnostics,
                        arguments.AttributeSyntaxOpt,
                        0,
                        "ByValTStr",
                        arguments.Attribute
                        );
                }
                else
                {
                    DecodeMarshalAsFixedString(ref arguments, messageProvider);
                }
                break;

            case Cci.Constants.UnmanagedType_VBByRefStr:
                if (target == AttributeTargets.Field)
                {
                    messageProvider.ReportMarshalUnmanagedTypeNotValidForFields(
                        arguments.Diagnostics,
                        arguments.AttributeSyntaxOpt,
                        0,
                        "VBByRefStr",
                        arguments.Attribute
                        );
                }
                else
                {
                    // named parameters ignored with no error
                    arguments
                    .GetOrCreateData <TWellKnownAttributeData>()
                    .GetOrCreateData()
                    .SetMarshalAsSimpleType(unmanagedType);
                }
                break;

            default:
                if (
                    (int)unmanagedType < 0 ||
                    (int)unmanagedType > MarshalPseudoCustomAttributeData.MaxMarshalInteger
                    )
                {
                    // Dev10 reports CS0647: "Error emitting attribute ..."
                    messageProvider.ReportInvalidAttributeArgument(
                        arguments.Diagnostics,
                        arguments.AttributeSyntaxOpt,
                        0,
                        arguments.Attribute
                        );
                }
                else
                {
                    // named parameters ignored with no error
                    arguments
                    .GetOrCreateData <TWellKnownAttributeData>()
                    .GetOrCreateData()
                    .SetMarshalAsSimpleType(unmanagedType);
                }
                break;
            }
        }