How to marshal a structure with a structure array inside?

G

Guest

Sirs

I have the foolowing structures in C


#define POLY_MAX 8 // Número máximo de lados em um polígon

typedef struct { // Um vértice do polígon
double u, v; // texture space coord
double sx, sy; // screen space coord
double x, y, z; // object space coord
} poly_vert

typedef struct { // um polígon
int n; // número de lado
poly_vert vert[POLY_MAX]
} poly

and I used this solution

C
[StructLayout(LayoutKind.Sequential, Pack=1)
public struct poly_ver
{
public Double u, v;
public Double sx, sy;
public Double x, y, z;
}

[StructLayout(LayoutKind.Sequential, Pack=1)
public struct poly // um polígon
{
public Int32 n; // número de lado
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)
public poly_vert[] vert
public poly (int N

n = N
vert = new poly_vert[4]



When I try to call this function in an exported Win32 DL


extern "C" __declspec(dllexport) int pmap_poly(poly *p, double ST[3][3])

C
[DllImport("ImageWarping.dll")
public static extern int pmap_poly(poly p, [In, Out] double[,] ST)

I get this error

An unhandled exception of type 'System.TypeLoadException' occurred in ImageWarpingClient.ex
Additional information: Can not marshal field vert of type poly: This type can not be marshaled as a structure field

Any help? How can I marshal the field vert

Thanks

Camil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top