写了个简单的dll尝试调用
testcpp.cpp:
extern “C” __declspec(dllexport) int testadd(int i)
{
return i++;
}
c#:
using System;
using System.Runtime.InteropServices;
public class MainClass
{
[DllImport("testcppdll.dll", EntryPoint = "testadd", CallingConvention = CallingConvention.StdCall)]
public static extern int testadd(int x);
static void Main()
{
Console.WriteLine(testadd(5));
}
}
运行的时候出现“请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。”错误
网上找了一堆都是说类型不匹配导致的问题,我可是把int long uint ulong Int16 Int32 Int64各种都试过排列组合。。。
当然这也是潜在可能的错误啦。
今天早上蛋疼地重新开了个程序用.net framework 2.0重新调用了一下,结果就pass了!
原来真正的罪魁祸首是.net framework的版本。。
继续尝试了一下,一直到.nf 3.5都ok