有两个非托管结构
typedef struct multipolynomial
{
int N;
int max_power;
double* X;
double** Y;
} multipolynomial;
typedef struct output
{
double d;
multipolynomial mp;
} output;
和相应的托管类似物
[StructLayoutAttribute(LayoutKind.Sequential)]
public unsafe class Multipolynomial
{
public int n;
public int max_power;
public double* X;
public double** Y;
}
[StructLayoutAttribute(LayoutKind.Sequential)]
public unsafe struct Output
{
public double d;
public Multipolynomial mp;
}
并且有原生功能
__declspec(dllexport) output __cdecl foo()
{
output out;
out.t = 1;
return out;
}
带托管签名
[DllImport("kernel.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern Output foo();
在这里崩溃
Output output = MathKernel.foo();
带有解释“方法的类型签名与 PInvoke 不兼容。”
请指出发生了什么问题?
PS:请注意,多项式结构的托管模拟是类