【发布时间】:2011-08-16 08:51:29
【问题描述】:
为什么Foo() 成功但Bar() 抛出BadImageFormatException?
using System.Runtime.InteropServices;
using System.Text;
static class Program
{
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int sprintf([Out] StringBuilder buf, string format, __arglist);
static void Main(string[] args)
{
Foo<int>(2); //Runs fine
Bar<int>(2); //Error: "The signature is incorrect"
}
static void Foo<T>(int a) { sprintf(new StringBuilder(8), "%d", __arglist(a)); }
static void Bar<T>(T a) { sprintf(new StringBuilder(8), "%d", __arglist(a)); }
}
【问题讨论】:
标签: c# .net generics variadic-functions cdecl