[Mono-list] P/Invoke question
Jonathan Pryor
jonpryor@vt.edu
Thu, 17 Mar 2005 07:15:39 -0500
On Thu, 2005-03-17 at 11:47 +0000, James Fitzsimons wrote:
> > For instance, you could declare the P/Invoke function
> > to take an array of CvPoint2D32f elements, then
> > construct this array in the code that calls this
> > function (the wrapper) with the appropriate size.
> > Perhaps, if you know CvPoint2D32f to be of type float,
> > you could even pass this array to the Marshal.Copy
> > function directly.
>
> This was actually what I originally had in mind, however CvPoint2D32f
> is actually a struct that looks like this (from memory)
> struct CvPoint2D32f
> {
> float x;
> float y;
> }
>
> So I guess the question becomes how do I marshal an array of structs?
> Or, could I marshal it as an array of floats of size 2 * number of
> CvPoint2D32f's, and put it back into struct form once it has been
> returned from the C function?
Structures can be marshaled just like any other type.
Struct CvPoint2D32f {
public float x;
public float y;
}
// ...
[DllImport ("...")]
public static extern void Foo (CvPoint2D32f[] points, int length);
- Jon