2

I want to return array of struct from the C++ dll to c#. I am trying it as following:

In c++ code:

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

and exported it in c++ like Some_API Vertex* GetVertices(Vertex*, float, int &);

and on C# side:

[DllImport("some.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr GetVertices(Vertex[] vertices, float aPos, ref int vSize);

and calling it like:

GetMeshSize(x_value, ref vSize);
            Vertex[] vertices = new Vertex[vSize];
            GetVertices(vertices, x_value, ref vSize);

Forget about the vSize and x_value for time being. My problem is I am not able to get the values of vertices in c#, I just want to know that how do I marshal array of the struct Vertex in c#. Note that I dont know anything about Marshal.

Vicky
  • 105
  • 1
  • 2
  • 10

0 Answers0