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

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);

 

posted on 2018-11-29 17:25 锋邢天下 阅读(...) 评论(...) 编辑 收藏

你可能感兴趣的:(C#和C++互相操作 结构体数组的传递)