2 messages in net.java.dev.jna.usersmapping unsigned char*
FromSent OnAttachments
mass...@tinvention.it/netDec 8, 2007 7:01 am 
Timothy WallDec 8, 2007 7:31 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:mapping unsigned char*Actions...
From:mass...@tinvention.it/net (mass@tinvention.it)
Date:Dec 8, 2007 7:01:22 am
List:net.java.dev.jna.users

I'm new to jna and I'm trying to wrap the api of a fingerprint scanner. Among the API functions I need to wrap is:

UFS_STATUS UFS_API UFS_Extract(HUFScanner hScanner, unsigned char* pTemplate, int* pnTemplateSize, int* pnEnrollQuality);

I got in trouble when i tried to retrieve the "unsigned char* pTemplate" parameter: pTemplate [out] Pointer to the template array; The array must be allocated in advance An example of correct use of this function in C is:

#define MAX_TEMPLATE_SIZE 384 UFS_STATUS ufs_res; HUFScaner hScanner; unsigned char Template[MAX_TEMPLATE_SIZE]; int TemplateSize; int nEnrollQuality; [...] ufs_res = UFS_Extract(hScanner, Template, &TemplateSize, &nEnrollQuality);

According to the very useful https://jna.dev.java.net/servlets/ReadMsg?list=users&msgNo=133 message i made this implementation in java with jna

In the Library interface: int UFS_Extract(Pointer scannerHandle, byte[] pTemplate, IntByReference pnTemplateSize, IntByReference pnEnrollQuality);

in the call:

byte[] pTemplate = new byte[384]; IntByReference pnTemplateSize = new IntByReference(); IntByReference pnEnrollQuality = new IntByReference(); returnCode = ufs.UFS_Extract(pp.getValue(), pTemplate, pnTemplateSize, pnEnrollQuality);

String s=Native.toString(pTemplate);

//String s = new String(pTemplate, 0, pnTemplateSize.getValue()); System.out.println("UFS_Extract extracted template: "+s);

I used information in thread https://jna.dev.java.net/servlets/ReadMsg?list=users&msgNo=148 to perform conversion from byte[] to String.

The problem is that I obtain something that is corrupt since the byte[] I receive is not converted considering that the chars are unsigned. How can I manage the fact that the C function returns unsigned chars, and make a correct conversion? Thanks a lot, Massimo