【发布时间】:2014-05-28 09:16:48
【问题描述】:
我是 C# 新手。
我有一个这样的 C 文件(我用它来制作 DLL 文件):
extern "C"
{
typedef int (__stdcall * t_fun)(int);
__declspec(dllexport) int __stdcall ExecuteC(int n, t_fun f)
{
return f(n);
}
}
然后我想使用 PInvoke 在我的 C# 代码中使用它。
public delegate int f_delegate(int n);
[DllImport("ExecuteC.dll")]
public static extern int ExecuteC(int n, f_delegate func);
public static int FunCS(int n){ return n; }
static void Main(string[] args)
{
int x = ExecuteC(13, FunCS);
System.Console.WriteLine(x.ToString());
}
当我启动我的程序时,它立即结束。 这里有什么问题?
【问题讨论】:
-
您需要进行一些诊断。立即结束是不好的。
标签: c# c delegates pinvoke function-pointers