[Mono-list] P/Invoke question

James Fitzsimons james.fitzsimons@gmail.com
Wed, 16 Mar 2005 23:29:57 +0000


--=-e7uH0GqnB6sPJHJZ5x8l
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hi all,

I have been doing a bunch of stuff with mashalling and P/Invoke to
create c# wrappers for the opencv C library and have had good success so
far, until now.

I am trying to call the following C function:

int cvFindChessBoardCornerGuesses( const CvArr* image, CvArr* thresh,
                                   CvMemStorage* storage,=20
				   CvSize board_size,
                                   CvPoint2D32f* corners,=20
				   int* corner_count=3DNULL );

Where the last two parameters are out values and the storage parameter
is allowed to be NULL.

I have the following definitions in my C# app:

[DllImport("cv")]
		private unsafe static extern int cvFindChessBoardCornerGuesses(
System.IntPtr img, System.IntPtr thresh, 			System.IntPtr storage,
CvSize etalonSize,
                        [Out] CvPoint2D32f* corners,=20
			[In, Out] int* cornerCount );


public unsafe void FindChessBoardCornerGuesses(CvImage image, CvImage
			thresh, CvSize etalonSize,
			out float[] corners, ref int cornerCount)
{
	System.IntPtr crns =3D new System.IntPtr();
	System.IntPtr crnCnt =3D new System.IntPtr();
		 =09
	CvPoint2D32f* crs =3D null;
		 =09
	cvFindChessBoardCornerGuesses( image.ImageHandle, thresh.ImageHandle,
System.IntPtr.Zero, etalonSize, crs, &cornerCount);
	=09
	corners =3D new float[cornerCount * 2];
	Marshal.Copy(crns, corners, 0, cornerCount * 2);
}

When I run however I get a null reference exception:
james@athos src $ MONO_LOG_LEVEL=3D"debug" MONO_LOG_MASK=3D"dll" mono
slamTest.exe=20
<snip>
Mono-INFO: DllImport attempting to load: 'cv'.
Mono-INFO: DllImport loading location: 'libcv.so'.
Mono-INFO: Probing 'cvFindChessBoardCornerGuessesA'.
Mono-INFO: Probing 'cvFindChessBoardCornerGuesses'.
Mono-INFO: Found as 'cvFindChessBoardCornerGuesses'.

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object
in (unmanaged) 0x2a981fb3e0
in <0x0000f> (wrapper managed-to-native)
Slam.CvCamera:cvFindChessBoardCornerGuesses
(intptr,intptr,intptr,Slam.CvSize,Slam.CvPoint2D32f*,int*)
in <0x0008b> Slam.CvCamera:FindChessBoardCornerGuesses
(Slam.CvImage,Slam.CvImage,Slam.CvSize,single[]&,int&)
in <0x001af> Slam.MainClass:Main (string[])

Can anyone offer any advice. Am I doing the right thing with my wrapping
functions?

Thanks for any assistance you can provide!
James
=20
--=20
It's 5.50 a.m.... Do you know where your stack pointer is ?

--=-e7uH0GqnB6sPJHJZ5x8l
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQBCOMFztf4qL6AoafMRAireAJwIsDWq2KN2jsjlgjUVB7kjg6lylwCg1o85
QvAE+Yp+RLBxjRK6Y89HbAI=
=hgw6
-----END PGP SIGNATURE-----

--=-e7uH0GqnB6sPJHJZ5x8l--