JNative 传递参数bug
下载JNative网址:http://sourceforge.net/projects/jnative/files/jnative/
下载JNative版本:JNative_1.4RC3_bin.zip
bug描述:
Test.dll中有个方法fnTest有五个参数,方法签名如下:
void fnTest(double a,double b,double c,double d,int e);
当用JNative调用时如下:
public void fnTest() throws NativeException, IllegalAccessException { JNative fnTest=null;
try { fnTest= new JNative("Test.dll", "fnTest"); fnTest.setParameter(0, Type.DOUBLE, "111.111"); fnTest.setParameter(1, Type.DOUBLE, "222.222");
fnTest.setParameter(2, Type.DOUBLE, "333.333");
fnTest.setParameter(3, Type.DOUBLE, "444.444");
fnTest.setParameter(4, Type.INT, "5"); fnTest.setRetVal(Type.VOID); fnTest.invoke();
} finally { if (fnTest!= null) { fnTest.dispose(); } } }
代码运行起来后,到 Test.dll中的fnTest方法,发现参数a=444.444 b=333.333 c=222.222 d=111.111
没有看源代码,具体原因不知道。
将代码修改如下:
public void fnTest() throws NativeException, IllegalAccessException { JNative fnTest=null; try { fnTest= new JNative("Test.dll", "fnTest"); fnTest.setParameter(3, Type.DOUBLE, "111.111"); fnTest.setParameter(2, Type.DOUBLE, "222.222");
fnTest.setParameter(1, Type.DOUBLE, "333.333");
fnTest.setParameter(0, Type.DOUBLE, "444.444");
fnTest.setParameter(4, Type.INT, "5"); fnTest.setRetVal(Type.VOID); fnTest.invoke(); } finally { if (fnTest!= null) { fnTest.dispose(); } } }
调用成功,问题搞定!!!