gpt4 book ai didi

c# - 从 C# Array MarshalAs 调用 C++ 有问题吗?

转载 作者:行者123 更新时间:2023-11-30 04:33:36 25 4
gpt4 key购买 nike

所以我在 C++ 库中有一个函数:

double MyFunc(double** data, int length)
{
//data elements are accessed like this
(*data)[i] = 5.0;
}

在 C# 中,我以这种方式访问​​此函数:

//import
[DllImport(@"MYDLL.dll")]
public static extern double MyFunc(ref double[] data, int length);
//usage
MyFunc(ref data, data.Length);

这很愚蠢,因为我宁愿写:

double MyFunc(double* data, int length)
{
//data elements are accessed like this
data[i] = 5.0;
}

问题是,我不知道如何从 C# 访问所需的 C++ 函数...我不太精通编码(marshal)处理值...我该怎么做?

最佳答案

您可以直接传递一个double[]

关于c# - 从 C# Array MarshalAs 调用 C++ 有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6714281/

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