C#和C++互相操作 结构体数组的传递

C++中结构体定义:

typedef struct // 平面
{
  double time; 
  float normal[3];
  float center[3]; 
} plane;

C++中方法声明:

public void GetPlanes(plane *planes, int size);

C#中结构体声明:

[StructLayout(LayoutKind.Sequential)]
public struct GPlane
{
  public double timestamp;
  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  public float[] normal;
  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  public float[] center;
}

C#中方法声明:

[DllImport(LibFileName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private static extern bool Pvr_getAirGlassPlanes([In, Out]GPlane[] plane, int size);

C#中调用该方法:

int size = 2;

GPlane[] plane = new GPlane[size];

Pvr_getAirGlassPlanes(plane, size);

上一篇:SQL 中的好习惯和坏习惯


下一篇:python-自定义异常,with用法