P / invoke System.ExecutionEngineException when passing an array as ref / out

Im using P / invoke for the unmanaged dll function swe_calc_ut.

int swe_calc_ut(double tjd_et, int ipl, int iflag, double *xx, char *serr)

The xx parameter means "an array of 6 doubles to store the result", and the serr parameter means "a character string to return error messages"


my c # code is as follows.

[DllImport("swedll32.dll")]
private static extern int swe_calc_ut(double tjd_ut, int ipl, int iflag, out double[] xx, out char[] serr);

double jul_day_UT=22000;
int p=3;
int iflag=64 * 1024;
double[] arr;
char[] serr;

int x = swe_calc_ut(jul_day_UT, p, iflag , out arr, out serr);

Now, when I execute the swe_calc_ut function, I get the error "Type Exception" Fixed System.ExecutionEngineException ".". I'm new to P / invoke, so I'm probably making a stupid mistake. I thought that these should be arrays since before, when I accidentally passed them by value, I did not get an error. I would really appreciate your help.

+3
2

out ref . , . #.

+6

C, , . , double [] double*. out ref, , , double**.

, , , . , . serr StringBuilder.

, , . serr. . , (.. StringBuilder ) . . , FEEE.

+5

Source: https://habr.com/ru/post/1763307/


All Articles