4 messages in net.java.dev.jna.usersRe: [jna-users] mapping problem
FromSent OnAttachments
LUCKY LUCKEMar 22, 2008 5:05 pm 
LUCKY LUCKEMar 22, 2008 5:30 pm 
Timothy WallMar 22, 2008 6:04 pm 
LUCKY LUCKEMar 24, 2008 4:07 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:Re: [jna-users] mapping problemActions...
From:LUCKY LUCKE (evsa@yahoo.gr)
Date:Mar 24, 2008 4:07:53 am
List:net.java.dev.jna.users

The native function seems to be working! IntByReference and byte[] finally did the job. Iam able to get the reader
status, to retrieve info, etc

THANK YOU A LOT TIMOTHY! Keep on the good job! THANK YOU!

evsav

----- Original Message ---- From: Timothy Wall <twal@dev.java.net> To: use@jna.dev.java.net Sent: Sunday, March 23, 2008 3:04:43 AM Subject: Re: [jna-users] mapping problem

On Mar 22, 2008, at 8:31 PM, LUCKY LUCKE wrote:

Hi Timothy

Your having been so patient with my questions gives me the courage to post again

Despite the many trial and error attempts, i have not been able so far to read a memory card or write to it as i dont do the right mapping of the native function parameters. Unfortunately i dont have any manufacturer manual. The only thing i know for sure is that the dataIn and dataOut params of the SCardComand are pointers to string arrays and are of type LPCSTR.

A quick google for the API shows this definition for Delphi:

Response = SCardComand (Handle, Cmd, CmdLen, DataIn, DataInLen, DataOut, DataOutLen ); LPINT Handle /* pointer to a 32 bit signed integer */ LPSTR Cmd /* pointer to a zero terminated string */ LPINT CmdLen /* pointer to a 32 bit signed integer */ LPSTR DataIn /* pointer to an array of byte or a string */ LPINT DataInLen /* pointer to a 32 bit signed integer */ LPSTR DataOut /* pointer to an array of byte or a string */ LPINT DataOutLen /* pointer to a 32 bit signed integer */ INT Response /* 32 bit signed integer */

You can use java.lang.String for a zero-terminated (read-only) string, but you must use byte[] if the native code writes to the memory you give it.

Note that the "len" arguments are all pointers to int, which implies that you may need to use IntByReference rather than a plain old "int". While this may just be symptomatic of the Delphi API (I know nothing of Delphi), an "int" given where "int*" is required would certainly cause a VM crash.