[Mono-list] P/Invoke question

Kelly Leahy kellyleahy@swbell.net
Wed, 16 Mar 2005 16:37:12 -0800 (PST)


--- Kelly Leahy <kellyleahy@swbell.net> wrote:
> However, I don't think this is right either.  I
> think
> perhaps your C declaration is either wrong, or the
> caller has to preallocate the array of CvPoint2D32f
> elements before calling this function. 

Looking at the documentation for this function at:

http://www.cs.bham.ac.uk/resources/courses/robotics/doc/opencvdocs/ref/OpenCVRef_3dReconstruction.htm#decl_cvFindChessBoardCornerGuesses

I was correct.

The caller is responsible for preallocating the array
of CvPoint2D32f records.

For the purposes of building a nice C# wrapper, you
could either take a "length" argument or use the array
length to determine how many points to handle.  I
think taking a length argument is cleaner, (and allows
the caller to use a subset of the array), but either
solution is possible.

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.

Kelly