i have following c++ structs:
typedef struct point { int x; int y; } point; typedef struct imtresult { int numberofpoints; point* vect_intima; point* vect_media; point* vect_adventitia; } imtresult;
where numberofpoints
length of each pointer of point
and c++ function:
bool setsecondpoint( int x, int y, imtresult* result );
how can marshall imtresult struct in c#? tried:
public struct imtresult { public int numberofpoints; public intptr vect_intima; public intptr vect_media; public intptr vect_adventitia; }
and tried manage myself 3 vectors using:
[dllimport("mydll.dll", callingconvention = callingconvention.cdecl)] public static extern bool setsecondpoint(int x, int y, [marshalas(unmanagedtype.struct)] ref imtresult result); public bool dllsetsecondpoint(int x, int y, ref imtresult result) { bool res = setsecondpoint(x, y, ref result); int structsize = marshal.sizeof(typeof(point)); point vect = new point(); intptr ptr = result.vect_media; (int = 0; < result.numberofpoints; i++) { point vect = (point) marshal.ptrtostructure(ptr, typeof(point)); ptr = (intptr)((int)ptr + structsize); } return res; }
but vect
results in vector x
, y
equal -1 . tried marshal attribute each of these vectors unsuccessfully. me?
in fact, there no problem @ all. code absolutely correct. thanks!
Comments
Post a Comment