C++DLL .h中
_declspec(dllexport) float _stdcall eAdd(const float fxw, const float fyw);
_declspec(dllexport) float _stdcall qAdd(float aw, float bw);
.cpp中
float _stdcall RealDLL::eAdd(const float fxw, const float fyw)
{
cout << fxw << endl;
cout << fyw << endl;
return fxw+fyw;
}
float _stdcall RealDLL::qAdd(float aw, float bw)
{
cout << aw << endl;
cout << bw << endl;
return aw + bw;
}
C#中
[DllImport(@"CFirstDLL.dll", EntryPoint = "eAdd", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
extern static float eAdd(float fx, float fy);
[DllImport(@"CFirstDLL.dll", EntryPoint = "qAdd", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
extern static float qAdd(float a, float b);
static void Main(string[] args)
{
float Py = 4.55F, Pz = 6.66F, Prx = 7.75F, Pry = 8.88f,;
float res = eAdd(Py, Pz);
float srf = qAdd(Prx, Pry);
}
结果:
问题: 两个函数的第一个参数都传输错误,C#中第二参数的值传给了DLL里的第一个参数,DLL中第二个参数为0。试了网上的好多种方法仍然没解决,求各位大佬帮忙看看是咋回事?