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

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!