internal void SetDllImportPseudoCustomAttribute(string dllName, string entryName, CallingConvention? nativeCallConv, CharSet? nativeCharSet, bool? bestFitMapping, bool? throwOnUnmappableChar, bool? setLastError, bool? preserveSig, bool? exactSpelling) { const short NoMangle = 0x0001; const short CharSetMask = 0x0006; const short CharSetNotSpec = 0x0000; const short CharSetAnsi = 0x0002; const short CharSetUnicode = 0x0004; const short CharSetAuto = 0x0006; const short SupportsLastError = 0x0040; const short CallConvMask = 0x0700; const short CallConvWinapi = 0x0100; const short CallConvCdecl = 0x0200; const short CallConvStdcall = 0x0300; const short CallConvThiscall = 0x0400; const short CallConvFastcall = 0x0500; // non-standard flags const short BestFitOn = 0x0010; const short BestFitOff = 0x0020; const short CharMapErrorOn = 0x1000; const short CharMapErrorOff = 0x2000; short flags = CharSetNotSpec | CallConvWinapi; if (bestFitMapping.HasValue) { flags |= bestFitMapping.Value ? BestFitOn : BestFitOff; } if (throwOnUnmappableChar.HasValue) { flags |= throwOnUnmappableChar.Value ? CharMapErrorOn : CharMapErrorOff; } if (nativeCallConv.HasValue) { flags &= ~CallConvMask; switch (nativeCallConv.Value) { case System.Runtime.InteropServices.CallingConvention.Cdecl: flags |= CallConvCdecl; break; case System.Runtime.InteropServices.CallingConvention.FastCall: flags |= CallConvFastcall; break; case System.Runtime.InteropServices.CallingConvention.StdCall: flags |= CallConvStdcall; break; case System.Runtime.InteropServices.CallingConvention.ThisCall: flags |= CallConvThiscall; break; case System.Runtime.InteropServices.CallingConvention.Winapi: flags |= CallConvWinapi; break; } } if (nativeCharSet.HasValue) { flags &= ~CharSetMask; switch (nativeCharSet.Value) { case CharSet.Ansi: case CharSet.None: flags |= CharSetAnsi; break; case CharSet.Auto: flags |= CharSetAuto; break; case CharSet.Unicode: flags |= CharSetUnicode; break; } } if (exactSpelling.HasValue && exactSpelling.Value) { flags |= NoMangle; } if (!preserveSig.HasValue || preserveSig.Value) { implFlags |= MethodImplAttributes.PreserveSig; } if (setLastError.HasValue && setLastError.Value) { flags |= SupportsLastError; } ImplMapTable.Record rec = new ImplMapTable.Record(); rec.MappingFlags = flags; rec.MemberForwarded = pseudoToken; rec.ImportName = this.ModuleBuilder.Strings.Add(entryName ?? name); rec.ImportScope = this.ModuleBuilder.ModuleRef.FindOrAddRecord(dllName == null ? 0 : this.ModuleBuilder.Strings.Add(dllName)); this.ModuleBuilder.ImplMap.AddRecord(rec); }
internal void SetDllImportPseudoCustomAttribute(string dllName, string entryName, CallingConvention?nativeCallConv, CharSet?nativeCharSet, bool?bestFitMapping, bool?throwOnUnmappableChar, bool?setLastError, bool?preserveSig, bool?exactSpelling) { const short NoMangle = 0x0001; const short CharSetMask = 0x0006; const short CharSetNotSpec = 0x0000; const short CharSetAnsi = 0x0002; const short CharSetUnicode = 0x0004; const short CharSetAuto = 0x0006; const short SupportsLastError = 0x0040; const short CallConvMask = 0x0700; const short CallConvWinapi = 0x0100; const short CallConvCdecl = 0x0200; const short CallConvStdcall = 0x0300; const short CallConvThiscall = 0x0400; const short CallConvFastcall = 0x0500; // non-standard flags const short BestFitOn = 0x0010; const short BestFitOff = 0x0020; const short CharMapErrorOn = 0x1000; const short CharMapErrorOff = 0x2000; short flags = CharSetNotSpec | CallConvWinapi; if (bestFitMapping.HasValue) { flags |= bestFitMapping.Value ? BestFitOn : BestFitOff; } if (throwOnUnmappableChar.HasValue) { flags |= throwOnUnmappableChar.Value ? CharMapErrorOn : CharMapErrorOff; } if (nativeCallConv.HasValue) { flags &= ~CallConvMask; switch (nativeCallConv.Value) { case System.Runtime.InteropServices.CallingConvention.Cdecl: flags |= CallConvCdecl; break; case System.Runtime.InteropServices.CallingConvention.FastCall: flags |= CallConvFastcall; break; case System.Runtime.InteropServices.CallingConvention.StdCall: flags |= CallConvStdcall; break; case System.Runtime.InteropServices.CallingConvention.ThisCall: flags |= CallConvThiscall; break; case System.Runtime.InteropServices.CallingConvention.Winapi: flags |= CallConvWinapi; break; } } if (nativeCharSet.HasValue) { flags &= ~CharSetMask; switch (nativeCharSet.Value) { case CharSet.Ansi: case CharSet.None: flags |= CharSetAnsi; break; case CharSet.Auto: flags |= CharSetAuto; break; case CharSet.Unicode: flags |= CharSetUnicode; break; } } if (exactSpelling.HasValue && exactSpelling.Value) { flags |= NoMangle; } if (!preserveSig.HasValue || preserveSig.Value) { implFlags |= MethodImplAttributes.PreserveSig; } if (setLastError.HasValue && setLastError.Value) { flags |= SupportsLastError; } ImplMapTable.Record rec = new ImplMapTable.Record(); rec.MappingFlags = flags; rec.MemberForwarded = pseudoToken; rec.ImportName = this.ModuleBuilder.Strings.Add(entryName ?? name); rec.ImportScope = this.ModuleBuilder.ModuleRef.FindOrAddRecord(dllName == null ? 0 : this.ModuleBuilder.Strings.Add(dllName)); this.ModuleBuilder.ImplMap.AddRecord(rec); }