4 messages in net.java.dev.jna.usersmapping 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:mapping problemActions...
From:LUCKY LUCKE (evsa@yahoo.gr)
Date:Mar 22, 2008 5:30:55 pm
List:net.java.dev.jna.users

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. I use the following code
to map the dataIn parameter

StringArray sarray = new StringArray(new WString[]{new WString("hello")});

Isn't this a pointer to a string array mapping? (StringArray extends Memory).
But when i try to write the above "hello" to the card with the command

lib.SCardComand(handle,new WString("Card,MemWrite,48,208"), new
NativeLong(), sarray, newNativeLong(208), new ArrayPointer(1), new
NativeLong());

i get a JVirtualMachine crash. Handle is a NativeLong variable, and ArrayPointer
is a Memory subclassing.

public static class ArrayPointer extends Memory {

public ArrayPointer(int size) { super(size); } }

Myquestions are: Isn't Memory type an eligible one to retrieve or pass astring
from / to a native function? Do i have to put the declarationsof StringArray and
ArrayPointer into the scope of SCard32 interface inorder to have an efficient
and working mapping?

public interface SCard32 extends StdCallLibrary {

SCard32 INSTANCE = (SCard32) Native.loadLibrary("SCard32",
SCard32.class);

public int SCardComand(NativeLong Handle, WString Cmd, NativeLong CmdLen, Memory dataIn, NativeLong dataInLen, Memory dataOut, NativeLong dataoutlen);

}

Dont forget to mention that
System.out.println(Native.toString(sarray.getByteArray(0, 8))); only prints 'h'

--- I tried every possible combination of jna types but i cant map the pointer to
string array (LPCSTR) type. I managed though to efficiently communicate with the card using Visual Basic!!! Is it possible to load an ActiveX dll using JNA? Is this a satisfactory solution??? Should i use C++ to build a bridge between my application and the hardware
driver???? (Giving up is not an option)

I have dried up!!! Ineed your expertise Timothy. How would you map such a function withLPCSTRs and
LPINTs (this is the only info i have about the nativefunction)

Thank you evsav