Jump to content
Excelsior Forums
oelke

xFunction.dll crashes JAVA

Recommended Posts

I try to call a function from a DLL with xFunction but it always crashes JAVA in xfunction.dll.

I'm not sure if I call the function correctly as I haven't found a similar sample for it.

The function in the DLL looks like this:

/*

Return pointer to template or NULL if any error happened

pDib - pointer to DIB (device-independent bitmap) of the fingerprint image

 (uncompressed, 8 bit per pixel, 256 color, grayscale, 500 dpi) (input)

size - size ot the memory block, returned the function (output)

quality - quality of the fingerprint image in the range 0...100 (output)

*/

char* WINAPI enroll(char* pDib, int &size, int& quality);

I have tried to call the function in JAVA like this:

xFunction f = new xFunction("sndFingerPrint", "CSTRING _enroll@12(CSTRING, int*, int*)");

Argument arg1=new Argument(ThumbPic, Argument.CSTRING);

Pointer arg2=Pointer.create("int*  ");

Pointer arg3=Pointer.create("int*  ");

String returnStr =(String) f.invoke(arg1, arg2, arg3);

mySize = ((Integer)arg2.deref()).intValue();

myQuality = ((Integer)arg3.deref()).intValue();

The xfunction.dll crashes with the call of f.invoke so I think it might have something to do with the parameter types I'm using.

Am I doing anything wrong here? The first parameter actually is a 120 KB bitmap filled in a Java String.

Maybe xFunction has a problem with that?

I hope someone can help me getting this to work.

Best Regards,

Andreas Oelke

Share this post


Link to post
Share on other sites

char* in your case points to raw data, whereas CSTRING should be used for zero-terminated character strings only. Use char* instead.

Share this post


Link to post
Share on other sites

How exactly would I write the Argument line then?

Now I use "Argument arg1=new Argument(ThumbPic, Argument.CSTRING); " to set the first Parameter to "ThumbPic".

How can I do that with type "char*"?

Share this post


Link to post
Share on other sites

Your code should look like this:

      xFunction f = new xFunction("sndFingerPrint", "char* _enroll@12(char*, int*, int*)");

      Argument arg1=Argument.create("char*", ThumbPic.toCharArray());

      Pointer arg2=Pointer.create("int*  ");

      Pointer arg3=Pointer.create("int*  ");

      Pointer myBitmapPtr =(Pointer) f.invoke(arg1, arg2, arg3);

      mySize = ((Integer)arg2.deref()).intValue();

      myQuality = ((Integer)arg3.deref()).intValue();

      try {

          char[] myBitmap = myBitmapPtr.createArray(mySize);

      } catch(NullDereferenceException e) {

      // NULL returned

      }

The only question is how can C-function enroll determine the size of its input array. Maybe size is both input and output parameter? In this case arg2 should be created appropriately.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×