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

梅尔尔

成员
加入
1月22,2021
消息
12
编程经验
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,901
地点
切萨皮克,va.
编程经验
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?
 
最佳 底部