我有以下结构定义:
#ifndef struct_emxArray_real_T
#define struct_emxArray_real_T
struct emxArray_real_T
{
real_T *data;
int32_T *size;
int32_T allocatedSize;
int32_T numDimensions;
boolean_T canFreeData;
};
#endif /*struct_emxArray_real_T*/并希望通过PInvoke在C#中使用它。该结构旨在表示一个矩阵。任何C#结构代码都将非常受欢迎。谢谢!
有人尝试使用here
[StructLayout(LayoutKind.Sequential, Size = 1)]
public unsafe struct mytype
{
public double* data;
public int* size;
public int allocatedSize;
public int numDimensions;
public bool canFreeData;
}但并没有让它工作。
发布于 2013-02-18 03:12:09
C#结构不支持指针类型。
相反,指针必须作为IntPtr进行移植;您可以使用Marshal类来解析指针。
因此,您应该编写如下内容
[StructLayout(LayoutKind.Sequential)]
public unsafe struct mytype
{
public IntPtr data;
public IntPtr size;
public int allocatedSize;
public int numDimensions;
public bool canFreeData;
}检查您的boolean_T类型的大小;您可能需要使用[MarshalAs(...)]属性指定正确的大小。
https://stackoverflow.com/questions/14924909
复制相似问题