我想将结构数组从C ++ dll返回到c#。我正在尝试如下:
在c ++代码中:
Vertex*
GetVertices(Vertex* vertices, float aPos, int& vSize) {
if ( !plane ) {
plane = new ClipPlane;
plane->type = PlaneType;
}
Vertex* v = plane->mesh->vertex;
vSize = plane->mesh->size*3;
vertices = v;
return vertices;
}
并将其导出为c ++,如Some_API Vertex* GetVertices(Vertex*, float, int &);
并在C#方面:
[DllImport("some.dll", CallingConvention = CallingConvention.Winapi)]
public static extern IntPtr GetVertices(Vertex[] vertices, float aPos, ref int vSize);
并将其称为:
GetMeshSize(x_value, ref vSize);
Vertex[] vertices = new Vertex[vSize];
GetVertices(vertices, x_value, ref vSize);
暂时忘掉vSize和x_value。我的问题是我无法在c#中获取顶点的值,我只是想知道如何在c#中编组struct Vertex的数组。请注意,我对马歇尔一无所知。