JNATIVE 调用DLL传参数问题
最近在调用读卡器的DLL文件 其中有个返回参数 试了很久 还是报错误码 求论坛牛人些帮忙看看 应该怎么传进去 下面贴码
DLL文件里面的说明
LONG
WINAPI
A6_Initialize
(
__in READERHANDLE hReader,
__in BYTE bResetMode,
__out PBYTE pbVerBuff,
__inout PDWORD pcbVerLength
);
参数
hReader 引用A6_Connect 返回的句柄值。
bResetMode 复位模式。可用值:
RESET_NOACTION 仅复位,不移动卡片。
RESET_EJECT 复位并移动读卡器内的卡片到前端持卡位。
RESET_RETAIN 复位并移动读卡器内的卡片到后端持卡位。
pbVerBuff 接收固件版本信息的缓冲区。
pcbVerLength 提供 pbVerBuff 参数的长度(字节数)并接收读卡器实际返回的长度。
返回值
如果函数调用成功,返回值为0, 其它值为错误码。
下面是自己的写调用代码
//读卡器复位
public int Initialize(String dllname,Pointer p,String mode,Pointer p1,Pointer p2){
try {
byte[] b = null;
b = ("RESET_EJECT").getBytes();
byte[] c = new byte[128];
int k = 0;
Pointer pArrIntInput = new Pointer(MemoryBlockFactory.createMemoryBlock(c.length));
for (int i = 0; i < c.length; i++) {
pArrIntInput.setByteAt(i, c[i]);
}
k = pArrIntInput.getSize();
System.out.println(pArrIntInput.getSize());
Pointer pArrIntInput1 = new Pointer(MemoryBlockFactory.createMemoryBlock(400));
pArrIntInput1.setIntAt(0, pArrIntInput.getSize());
JNative jnative = new JNative(dll_name,"A6_Initialize");
jnative.setRetVal(Type.INT);//
jnative.setParameter(0,p.getAsInt(0));//
jnative.setParameter(1,Type.VOID,b);//
jnative.setParameter(2,pArrIntInput);//
jnative.setParameter(3,pArrIntInput1);//
jnative.invoke(); //
System.out.println(jnative.getRetValAsInt()+"||||");//获取返回值并显示
int k1 = jnative.getRetValAsInt();
jnative.dispose();
return k;// 函数返回值
} catch (NativeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 1;
}
始终感觉pcbVerLength 这个值传的有问题,所有导致错误码,现在传参无效或为null