[英]Pinvoke for struct
我有以下结构定义:
#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#结构代码都将非常感激。 谢谢!
[StructLayout(LayoutKind.Sequential, Size = 1)]
public unsafe struct mytype
{
public double* data;
public int* size;
public int allocatedSize;
public int numDimensions;
public bool canFreeData;
}
但没有得到它的工作。
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(...)]
属性来指定正确的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.