Question Converting a C++ function call to C#

Maylar

Member
Joined
Jan 22, 2021
Messages
16
Programming Experience
10+
I have a DLL that uses arguments that are pointers:

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

I can fix the array syntax but what do I do about the pointers?

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 tells me :
Error 1 Pointers and fixed size buffers may only be used in an unsafe context

TIA
 
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?
 
Back
Top Bottom