KangFeng2016 2019-07-10 15:15 采纳率: 0%
浏览 328

C#向C++ DLL传递参数出现参数顺序和个数对应错误的问题

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。试了网上的好多种方法仍然没解决,求各位大佬帮忙看看是咋回事?

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-07-11 00:01
    关注

    c++程序编译成32bit
    C#强制也编译成32bit

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog