tags:

views:

339

answers:

2

Hi!

How do i map this function with JNA:

Delphi code:

function getData(InData1: PChar; 
                 InData2: PChar; 
                 Data: TArray16; 
                 var OutData1: PChar; 
                 var OutData2: PChar): integer; stdcall;

with: TArray16 = array[0..15] of char;

The int value that is returned can be 0 for Error or 1 for right execution;

My suggestion is:

Java code:

int getData(String inData1, 
            String inData2, 
            byte[] data, 
            byte[] outData1
            byte[] outData2);

The problem is that the function of the dll returns 0. I also tried other Datatypes, but it hasn't worked jet. I think the problem is that the dll function can't write to the parameters outData1 and outData2.

Who can help me?....Thanks!!

A: 

try java.nio.ByteBuffer for OutData1 and OutData2

EDIT

And can you write an equivalent of this function in in c++? if it is like this:

int getData(const char* InData1, const char* InData2, char[] Data, char** OutData1, char** OutData2);

then mapping would be

int getData(String InData1, String InData2, ByteBuffer Data, ByteByReference OutData1, ByteByReference OutData2);
tulskiy
A: 

Thank you for your answer!

"try java.nio.ByteBuffer for OutData1 and OutData2"

I tried this mapping now:

Java code:

int getData(String inData1, String inData2, byte[] data, ByteBuffer outData1 ByteBuffer outData2);

The function now returns 1 (perhaps there has been allocated enough memory now), but the data that has been written to outData1 and outData2 is always the same, although it depends on inData1, inData2 and data (I have changed it 5 times to test it with other values).

I used this functions a ByteBuffer b:

b = ByteBuffer.allocate(int capacity) and b.array() to get back a byte array.

*"And can you write an equivalent of this function in in c++? if it is like this:

int getData(const char* InData1, const char* InData2, char[] Data, char** OutData1, char** OutData2); then mapping would be

int getData(String InData1, String InData2, ByteBuffer Data, ByteByReference OutData1, ByteByReference OutData2);"*

No I can't. It is not my dll and the author will not change it. :-(

Sorry, I didn't see your answer. Did you solve the problem? Did you try using CharBuffer for InData1 and InData2 adding zeros at the end in case jna does not null terminate the String?
tulskiy