日期:2014-05-20  浏览次数:20711 次

>>>> 请教用jawind如何获取dll中方法的返回值? <<<<
在DLL中有一个方法GetBalance(String snh, String pwd) 返回值为String

请问我这样写
try {
FuncPtr GetBalance = new FuncPtr("Users.DLL", "GetBalance");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeStringUnicode(smsProperties.getUserID());
leos.writeStringUnicode(smsProperties.getSerialPassword());
GetBalance.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);
} catch (COMException e) {e.printStackTrace();} 

下面该如何获取GetBalance的返回值呢?

------解决方案--------------------
invoke调用后将输出一组字节数组,对这个数组进行处理就可以了
Java code
..
byte[] result = funcPtr.invoke(..);

// wrap result in a LittleEndianInputStream
LittleEndianInputStream leis = new LittleEndianInputStream(new ByteArrayInputStream(result));

// any [retval] values are placed first
int retVal = leis.readInt();

// and then follows any [out] values
int outVal = leis.readInt();
..

------解决方案--------------------
楼上对