我有不安全的课程Multipolynomial
:
[StructLayoutAttribute(LayoutKind.Sequential)]
public unsafe class Multipolynomial
{
private int _n;
private int _max_power;
//get/set code below for _n and _max_power
...
public double* X { get; set; }
public double** Y { get; set; }
}
我有两个类只包含双精度和多项式属性:
[StructLayoutAttribute(LayoutKind.Sequential)]
public unsafe class Input
{
public double S_M { get; set; }
public Multipolynomial C_x_M { get; set; }
...
public Input()
{
C_x_M = new Multipolynomial();
...
}
}
和
[StructLayoutAttribute(LayoutKind.Sequential)]
public unsafe class Output
{
//very same as Input
...
}
并且有dummy_solution
非托管签名的功能
KERNEL_API output dummy_solution(input *in_p); //input and output are unmanaged structs
和托管签名
[DllImport("kernel.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Output dummy_solution(Input in_p);
问题是当我尝试执行代码时
Input input = new Input();
Output output = new Output();
MathKernel.no_solution(input); //works great except it does nothing and returns nothing =P
output = MathKernel.dummy_solution(input); //does nothing, simply returns empty Output object and crashes
它抛出了XamlParseException
带有内部异常的异常{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
。
no_solution
函数只是具有非托管签名的虚拟测试函数
KERNEL_API void no_solution(input *in_p);
和托管签名
[DllImport("kernel.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void no_solution(Input in_p);
因此我得出结论,返回输出对象有问题。老实说,我是编组这样可怕的事情的新手,所以也许有一些我看不到的丑陋愚蠢的胡须。
Please point out whats wrong or give an advice how to build unmanaged function which simply gets class Input and returns class Output.