教程:在同一个调试会话中调试 C# 和 C++
C# 中的可变参数方法(VarArgs)
C/C++编写的函数可能用可变参数,在C++/C#混合编程时,如何调用在 dll 中的这样的函数呢?
可以通过使用 __arglist 这个不常见的关键字来进行可变参数函数的导入。
void axlog(unsigned int log_type, const char *format, ...);
使用可变参数列表。
[DllImport("AxTraceDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void axlog(uint log_type, string message, __arglist);
...
axlog(4, "Hello %s.", __arglist("world"));
这样就不能使用可变参数列表了。
[DllImport("AxTraceDll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void axlog(uint log_type, string message);
...
axlog(4, "Hello world.");
原文:https://www.cnblogs.com/octoberkey/p/14774059.html