问题 将C ++函数调用转换为C#

Maylar

新成员
已加入
2021年1月22日
留言内容
4
编程经验
10+
我有一个使用指针参数的DLL:

C++ prototype:
void __cdecl Rgp(double X[], double Y[], double *slope, double *offset, int32_t n_input);

我可以修复数组语法,但是如何处理指针?

C# prototype:
[DllImport("linearize_r01.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Rgp(
            double[] X,
            double[] Y,
            double *slope,
            double *offset,
            Int32 n_input);

Visual Studio告诉我:
错误1指针和固定大小的缓冲区只能在不安全的上下文中使用

TIA
 

跳伞

工作人员
已加入
2019年4月6日
留言内容
2,533
地点
弗吉尼亚州切萨皮克
编程经验
10+
Is the slope and offset actually used as pass by reference so that values can be returned out of the function? If so I think the P/Invoke documentation has some notes on how to deal with those. I can't check right now, but it may be as simple as using out, but it maybe more complex where you need to decorate those out parameters with something else?
 
最佳 底部