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".