1 message in net.java.dev.jna.usersreturn double[] argument by reference...
FromSent OnAttachments
Mr Young-soo SongMar 5, 2008 6:24 pm 
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:return double[] argument by reference from DLLActions...
From:Mr Young-soo Song (ysso@yahoo.co.kr)
Date:Mar 5, 2008 6:24:44 pm
List:net.java.dev.jna.users

You're definately right ,

1. I found *8 is really didn't work. So I eliminated *8 then it worked. I didn't realize Double.SIZE return as bit number. 2. double[] is also OK and easy way.

Many thanks for your correction.

your previous code was 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.

On Mar 5, 2008, at 3:25 AM, Mr Young-soo Song wrote:

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) ;

}

A double[] argument would be the simplest mapping, and the preferred one.

Memory dblPtr = new Memory(100*Double.SIZE) ;

ret = lib.callByRef( 100, dblPtr);

double[] x = dblPtr.getDoubleArray(0, 100);

This is actually incorrect, since Double.SIZE is in bits. You are allocating 8 times the amount of memory actually required, so it won't actually cause a failure. If you're going to use Memory, you would want to set the size to "count * Double.SIZE / 8".