internal StructLayoutAttribute(LayoutKind layoutKind, int pack, int size, System.Runtime.InteropServices.CharSet charSet)
 {
     this._val    = layoutKind;
     this.Pack    = pack;
     this.Size    = size;
     this.CharSet = charSet;
 }
        static string MakeDllImportArguments(string entryPoint, System.Runtime.InteropServices.CharSet charSet,
                                             bool setLastError, bool exactSpelling, bool preserveSig,
                                             System.Runtime.InteropServices.CallingConvention callingConvention,
                                             bool bestFitMapping, bool throwOnUnmappableChar)
        {
            var retval = new StringBuilder();

            if (!String.IsNullOrWhiteSpace(entryPoint))
            {
                retval.Append(", EntryPoint=\"" + entryPoint + '"');
            }
            if (charSet != DefaultDllImportAttribute.CharSet)
            {
                retval.Append(", CharSet = System.Runtime.InteropServices.CharSet." + charSet.ToString());
            }

            MakeDllImportArgument(retval, "SetLastError", setLastError, DefaultDllImportAttribute.SetLastError);
            MakeDllImportArgument(retval, "ExactSpelling", exactSpelling, DefaultDllImportAttribute.ExactSpelling);
            MakeDllImportArgument(retval, "PreserveSig", preserveSig, DefaultDllImportAttribute.PreserveSig);

            if (callingConvention != DefaultDllImportAttribute.CallingConvention)
            {
                retval.Append(", CallingConvention=" + callingConvention.ToString());
            }

            MakeDllImportArgument(retval, "BestFitMapping", bestFitMapping, DefaultDllImportAttribute.BestFitMapping);
            MakeDllImportArgument(retval, "ThrowOnUnmappableChar", throwOnUnmappableChar, DefaultDllImportAttribute.ThrowOnUnmappableChar);

            return(retval.ToString());
        }
Ejemplo n.º 3
0
 internal DllImportAttribute(string dllName, string entryPoint, System.Runtime.InteropServices.CharSet charSet, bool exactSpelling, bool setLastError, bool preserveSig, System.Runtime.InteropServices.CallingConvention callingConvention, bool bestFitMapping, bool throwOnUnmappableChar)
 {
     this._val                  = dllName;
     this.EntryPoint            = entryPoint;
     this.CharSet               = charSet;
     this.ExactSpelling         = exactSpelling;
     this.SetLastError          = setLastError;
     this.PreserveSig           = preserveSig;
     this.CallingConvention     = callingConvention;
     this.BestFitMapping        = bestFitMapping;
     this.ThrowOnUnmappableChar = throwOnUnmappableChar;
 }
 internal DllImportAttribute(string dllName, string entryPoint, System.Runtime.InteropServices.CharSet charSet, bool exactSpelling, bool setLastError, bool preserveSig, System.Runtime.InteropServices.CallingConvention callingConvention, bool bestFitMapping, bool throwOnUnmappableChar)
 {
     this._val = dllName;
     this.EntryPoint = entryPoint;
     this.CharSet = charSet;
     this.ExactSpelling = exactSpelling;
     this.SetLastError = setLastError;
     this.PreserveSig = preserveSig;
     this.CallingConvention = callingConvention;
     this.BestFitMapping = bestFitMapping;
     this.ThrowOnUnmappableChar = throwOnUnmappableChar;
 }
        internal static Attribute GetCustomAttribute(RuntimeType type)
        {
            if (!IsDefined(type))
            {
                return(null);
            }
            int        packSize  = 0;
            int        classSize = 0;
            LayoutKind auto      = LayoutKind.Auto;

            switch ((type.Attributes & TypeAttributes.LayoutMask))
            {
            case TypeAttributes.AnsiClass:
                auto = LayoutKind.Auto;
                break;

            case TypeAttributes.SequentialLayout:
                auto = LayoutKind.Sequential;
                break;

            case TypeAttributes.ExplicitLayout:
                auto = LayoutKind.Explicit;
                break;
            }
            System.Runtime.InteropServices.CharSet none = System.Runtime.InteropServices.CharSet.None;
            TypeAttributes attributes2 = type.Attributes & TypeAttributes.CustomFormatClass;

            if (attributes2 == TypeAttributes.AnsiClass)
            {
                none = System.Runtime.InteropServices.CharSet.Ansi;
            }
            else if (attributes2 == TypeAttributes.UnicodeClass)
            {
                none = System.Runtime.InteropServices.CharSet.Unicode;
            }
            else if (attributes2 == TypeAttributes.AutoClass)
            {
                none = System.Runtime.InteropServices.CharSet.Auto;
            }
            type.GetRuntimeModule().MetadataImport.GetClassLayout(type.MetadataToken, out packSize, out classSize);
            if (packSize == 0)
            {
                packSize = 8;
            }
            return(new StructLayoutAttribute(auto, packSize, classSize, none));
        }
 public DefaultCharSetAttribute(System.Runtime.InteropServices.CharSet charSet)
 {
     this._CharSet = charSet;
 }
Ejemplo n.º 7
0
 public DynamicDllImport(string dllName, System.Runtime.InteropServices.CharSet charSet = System.Runtime.InteropServices.CharSet.Auto, System.Runtime.InteropServices.CallingConvention callingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)
 {
     this.dllName = dllName;
     this.CharSet = charSet;
     this.CallingConvention = callingConvention;
 }
 public DefaultCharSetAttribute(System.Runtime.InteropServices.CharSet charSet)
 {
 }
Ejemplo n.º 9
0
 public MethodBuilder DefinePInvokeMethod(string name, string dllName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)
 {
     return(default(MethodBuilder));
 }
Ejemplo n.º 10
0
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            string str;

            if ((method.Attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)
            {
                return(null);
            }
            MetadataImport    metadataImport  = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
            string            importDll       = null;
            int               metadataToken   = method.MetadataToken;
            PInvokeAttributes bestFitUseAssem = PInvokeAttributes.BestFitUseAssem;

            metadataImport.GetPInvokeMap(metadataToken, out bestFitUseAssem, out str, out importDll);
            System.Runtime.InteropServices.CharSet none = System.Runtime.InteropServices.CharSet.None;
            switch ((bestFitUseAssem & PInvokeAttributes.CharSetAuto))
            {
            case PInvokeAttributes.BestFitUseAssem:
                none = System.Runtime.InteropServices.CharSet.None;
                break;

            case PInvokeAttributes.CharSetAnsi:
                none = System.Runtime.InteropServices.CharSet.Ansi;
                break;

            case PInvokeAttributes.CharSetUnicode:
                none = System.Runtime.InteropServices.CharSet.Unicode;
                break;

            case PInvokeAttributes.CharSetAuto:
                none = System.Runtime.InteropServices.CharSet.Auto;
                break;
            }
            System.Runtime.InteropServices.CallingConvention cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
            switch ((bestFitUseAssem & PInvokeAttributes.CallConvMask))
            {
            case PInvokeAttributes.CallConvStdcall:
                cdecl = System.Runtime.InteropServices.CallingConvention.StdCall;
                break;

            case PInvokeAttributes.CallConvThiscall:
                cdecl = System.Runtime.InteropServices.CallingConvention.ThisCall;
                break;

            case PInvokeAttributes.CallConvFastcall:
                cdecl = System.Runtime.InteropServices.CallingConvention.FastCall;
                break;

            case PInvokeAttributes.CallConvWinapi:
                cdecl = System.Runtime.InteropServices.CallingConvention.Winapi;
                break;

            case PInvokeAttributes.CallConvCdecl:
                cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
                break;
            }
            bool exactSpelling         = (bestFitUseAssem & PInvokeAttributes.NoMangle) != PInvokeAttributes.BestFitUseAssem;
            bool setLastError          = (bestFitUseAssem & PInvokeAttributes.SupportsLastError) != PInvokeAttributes.BestFitUseAssem;
            bool bestFitMapping        = (bestFitUseAssem & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (bestFitUseAssem & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;

            return(new DllImportAttribute(importDll, str, none, exactSpelling, setLastError, (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL, cdecl, bestFitMapping, throwOnUnmappableChar));
        }
Ejemplo n.º 11
0
 public DynamicDllImport(string dllName, System.Runtime.InteropServices.CharSet charSet = System.Runtime.InteropServices.CharSet.Auto, System.Runtime.InteropServices.CallingConvention callingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)
 {
     this.dllName           = dllName;
     this.CharSet           = charSet;
     this.CallingConvention = callingConvention;
 }
 public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] returnTypeRequiredCustomModifiers, System.Type[] returnTypeOptionalCustomModifiers, System.Type[] parameterTypes, System.Type[][] parameterTypeRequiredCustomModifiers, System.Type[][] parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)
 {
     throw null;
 }
 public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type?returnType, System.Type[]?parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)
 {
     throw null;
 }
Ejemplo n.º 14
0
        public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)
        {
            Contract.Ensures(Contract.Result <System.Reflection.Emit.MethodBuilder>() != null);

            return(default(MethodBuilder));
        }
Ejemplo n.º 15
0
 public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)
 {
     throw new PlatformNotSupportedException();
 }