我正在尝试使用 P/Invoke 调用第三方本机 DLL 中的一些函数。但我不断收到 FatalExecutionEngine 错误。可能我在数据编组方面犯了一些错误,或者?
这是我正在尝试使用的本机功能:
__declspec(dllexport) void dw_mm_directional_spectrum_initialise(
struct dw_mm_directional_spectrum_T* directional_spectrum
, const enum dw_buoy_type_T buoy_type
, const unsigned char status[ /* NULL || sample_count */ ]
, const double v[ /* sample_count */ ]
, const double n[ /* sample_count */ ]
, const double w[ /* sample_count */ ]
, const unsigned int sample_count);
这是通过指针返回的本机结构:
struct dw_mm_directional_spectrum_T{
signed char error_code;
double* c_vv;
double* c_nn;
double* c_ww;
double* c_nw;
double* q_vn;
double* q_vw;
unsigned short output_size;
double fraction_of_segments_used;
unsigned char* list_of_used_segments;
unsigned short list_of_used_segments_size;
};
这是 C# 程序中的结构定义:
[StructLayout(LayoutKind.Sequential)]
struct datawell{
Byte error_code;
double[] c_vv;
double[] c_nn;
double[] c_ww;
double[] c_nw;
double[] q_vn;
double[] q_vw;
ushort output_size;
double fraction_of_segments_used;
IntPtr list_of_used_segments;
ushort list_of_used_segments_size;
};
我的 DLLimport 签名:
[DllImport("libwaves.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void dw_mm_directional_spectrum_initialise(
out datawell dw,
Byte buoy_type,
Byte[] status,
double[] v,
double[] n,
double[] w,
ushort sample_count);
这就是我在 C# 程序中使用该函数的方式:
double[] vertical = new double[512];
double[] north = new double[512];
double[] west = new double[512];
Byte[] status = new Byte[512];
datawell dw_test = new datawell();
ushort cnt = 512;
//dummy data generation
for(int i=0;i<512;i++){
status[i]=1;
vertical[i]=i*1.0;
north[i]=i*1.0;
west[i]=i*1.0;
}
dw_mm_directional_spectrum_initialise(out dw_test,0,status, vertical, north,west,cnt);
任何帮助将不胜感激。
问候,
杰尔