gpt4 book ai didi

c# - 从 C++ DLL 中编写的 C++ 方法返回数据到 C#

转载 作者:行者123 更新时间:2023-11-28 07:37:30 27 4
gpt4 key购买 nike

<分区>

我可以返回一个数字,例如double从C++ DLL中编写的C++方法转化为C#

C++ 方面

__declspec(dllexport) double GetData()
{
double data = 5;

return data;
}

C# 端

[DllImport("data_acquisition_sys.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double GetData();
double data = GetData();

但是如果我想像上面那样返回一个double*或者double[]的数组,只需要改变返回值就可以了

__declspec(dllexport) double* GetData()  //C++
public static extern double[] GetData(); //C#

出现以下错误

Unhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination.

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com