

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
2 messages in net.java.dev.jna.usersRe: [jna-users] mapping unsigned char*| From | Sent On | Attachments |
|---|---|---|
| mass...@tinvention.it/net | Dec 8, 2007 7:01 am | |
| Timothy Wall | Dec 8, 2007 7:31 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] mapping unsigned char* | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Dec 8, 2007 7:31:16 am | |
| List: | net.java.dev.jna.users | |
Print the contents of the Java byte[] and compare with what you get in C. You should get identical values; there is no "conversion" between signed and unsigned to be done.
When printing each Java byte, be sure to do (((int)byteValue)&0xFF) to get the unsigned value.
* is the template *supposed* to be a human-readable string? * if so, what character encoding is your library using? if not the platform default, you'll need to set jna.encoding to ensure the proper conversion from byte[] to String.
On Dec 8, 2007, at 10:01 AM, mass...@tinvention.it/net wrote:
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







