Thanks! Timothy~
Now I got the array return values via calling by reference using Memory class.
Here is sample code for dummies like me ^^;
C Code in DLL
extern "C" __declspec(dllexport) double callByRef(int a,double b[])
// JNI mapping
NativeLibrary.addSearchPath("genDLL","C:\\project\\vc_project\\GenDLL\\debug");
testLib lib = (testLib) Native.loadLibrary ("genDLL",testLib.class);
public interface testLib extends StdCallLibrary
{
double callByRef(int a,Memory b) ;
}
Memory dblPtr = new Memory(100*Double.SIZE) ;
ret = lib.callByRef( 100, dblPtr);
double[] x = dblPtr.getDoubleArray(0, 100);
Date: Tue, 04 Mar 2008 08:43:18 -0500
From: Timothy Wall <twal...@dev.java.net>
Content-type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Subject: [jna-users] Re: call by reference of double array
On Mar 3, 2008, at 10:42 PM, Mr Young-soo Song wrote:
Thanks for your answer.
But I couldn't get the right value yet.
I'd like to get the double array output from DLL by calling by
reference.
If you provide any sample code of doing this.
It would be great to understand how to use it.
Could you give me a example for Memory or DoubleBuffer?
void getValues(double[] array)
void getValues(Pointer array)
void getValues(DoubleBuffer array);
array = new double[1024];
array = new Memory(1024 * Double.SIZE*8);
array = DoubleBuffer.allocate(1024); // on heap
array =
ByteBuffer.allocateDirect(1024*Double.SIZE*8).asDoubleBuffer(); // as
direct (native) buffer
This assumes that the "byref doubleArray" is a pointer to memory.