>>>> 请教用jawind如何获取dll中方法的返回值?

时间:2022-02-02 00:26:45
在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的返回值呢?

10 个解决方案

#1


invoke调用后将输出一组字节数组,对这个数组进行处理就可以了
..
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();
.. 

#2


楼上对

#3


我是这样写的: 
public class register {
public static void main(String[] args) throws Exception {
String output = testFunc("test", "123");
System.out.println(output);
}
public static String testFunc(String sn, String pwd) throws Exception{
  try{
FuncPtr func = new FuncPtr("VBSDK.DLL", "Register");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeStringUnicode(sn);
leos.writeStringUnicode(pwd);
byte[] result = funcReg.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);

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

// any [retval] values are placed first
return leis.readStringUnicode();
} catch (COMException e){
e.printStackTrace();
throw e;} 
编译成功,但是运行java register 时要报错:

org.jawin.COMException: 8007007f: ???????¨????ò??
        at org.jawin.Bootstrap.loadFunction(Native Method)
        at org.jawin.FuncPtr.<init>(FuncPtr.java:80)
        at register.smsRegister(register.java:26)
        at register.main(register.java:19)
Exception in thread "main" org.jawin.COMException: 8007007f: ???????¨????ò??
        at org.jawin.Bootstrap.loadFunction(Native Method)
        at org.jawin.FuncPtr.<init>(FuncPtr.java:80)
        at register.smsRegister(register.java:26)
        at register.main(register.java:19)

#4


再请教下,我的DLL文件是放在 
%JAVA_HOME%\bin 路径下的,这样正确吗?

#5


放在system32下

#6


这个问题有人回答吗?我也遇到了。
org.jawin.COMException: 8007007f: 
该错误是指未找到dll中的指定函数,同时说明已找到了dll文件。
如果是org.jawin.COMException: 8007007e: 错误的话,则说明未找到dll文件

请大家看看我的代码,帮我分析一下:
import java.io.ByteArrayInputStream;
import org.jawin.COMException;
import org.jawin.FuncPtr;
import org.jawin.ReturnFlags;
import org.jawin.io.LittleEndianInputStream;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.io.NakedByteStream;

public class NativeDll {

public static void main(String[] args) throws Exception {
//代码段1
FuncPtr funcP = new FuncPtr("Printf.dll", "calc");
String marshal = "II:I:L4L4";
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(4);
leos.writeInt(3);
byte[] res = funcP.invoke(marshal, 12, nbs, null, ReturnFlags.CHECK_W32);
ByteArrayInputStream bais = new ByteArrayInputStream(res);
LittleEndianInputStream leis = new LittleEndianInputStream(bais);
int result = leis.readInt();
System.out.println(result);
//代码段2
// FuncPtr funcP = new FuncPtr("USER32.DLL", "MessageBoxW");
// NakedByteStream nbs = new NakedByteStream();
// LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
// leos.writeInt(0);
// leos.writeStringUnicode("Google的浏览器和云计算在忽悠谁?");
// leos.writeStringUnicode("Jawin窗口标题");
// leos.writeInt(0);
// byte[] res = funcP.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);
// ByteArrayInputStream bais = new ByteArrayInputStream(res);
// LittleEndianInputStream leis = new LittleEndianInputStream(bais);
// int result = leis.readInt(); // the out param
// System.out.println(result);
}
}
其中将代码段1注释掉代码段2恢复时,程序运行正常,这说明我的jawin工程搭建没有问题;
将代码段1恢复代码段2注释掉时,程序运行第一行
"FuncPtr funcP = new FuncPtr("Printf.dll", "calc");"时就报8007007f错误;
我试过很多次,未果,在网上也没找着相关的解决办法。
是不是用jawin不能用来调用自定义的DLL呀?
我想应该不甚于吧。
请大家多多关注JAVA在这方面的应用,
同时也请高手指点指点!
我们真的很需要你们的帮助!
先谢谢啦!
我的邮箱:wolfware@yeah.net
我的MSN:hefusheng@hotmain.com,请附言:jawin

#7


我也遇到这些问题了,,始终没有解决--那为技术高手指点下,分享下经验--谢谢!!!!!!!!!!

#8


org.jawin.COMException: 8007007f: 的问题我解决了,是因为自己做的dll是VC做的,函数名称后面要加"@n"即可,如函数的参数有k个,则n=k*4,如没有参数n=0,2个参数n=8,4个参数n=16;
如下:
   FuncPtr funcP = new FuncPtr("Printf.dll", "calc@16");

#9


回复于:2010-10-21 15:14:07org.jawin.COMException: 8007007f: 的问题我解决了,是因为自己做的dll是VC做的,函数名称后面要加"@n"即可,如函数的参数有k个,则n=k*4,如没有参数n=0,2个参数n=8,4个参数n=16;
如下:
  FuncPtr funcP = new FuncPtr("Printf.dll", "calc@16");
 
 
我得加上@4也不行啊。

#10


人才,用extern "C" 生成标准dll

#1


invoke调用后将输出一组字节数组,对这个数组进行处理就可以了
..
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();
.. 

#2


楼上对

#3


我是这样写的: 
public class register {
public static void main(String[] args) throws Exception {
String output = testFunc("test", "123");
System.out.println(output);
}
public static String testFunc(String sn, String pwd) throws Exception{
  try{
FuncPtr func = new FuncPtr("VBSDK.DLL", "Register");
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeStringUnicode(sn);
leos.writeStringUnicode(pwd);
byte[] result = funcReg.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);

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

// any [retval] values are placed first
return leis.readStringUnicode();
} catch (COMException e){
e.printStackTrace();
throw e;} 
编译成功,但是运行java register 时要报错:

org.jawin.COMException: 8007007f: ???????¨????ò??
        at org.jawin.Bootstrap.loadFunction(Native Method)
        at org.jawin.FuncPtr.<init>(FuncPtr.java:80)
        at register.smsRegister(register.java:26)
        at register.main(register.java:19)
Exception in thread "main" org.jawin.COMException: 8007007f: ???????¨????ò??
        at org.jawin.Bootstrap.loadFunction(Native Method)
        at org.jawin.FuncPtr.<init>(FuncPtr.java:80)
        at register.smsRegister(register.java:26)
        at register.main(register.java:19)

#4


再请教下,我的DLL文件是放在 
%JAVA_HOME%\bin 路径下的,这样正确吗?

#5


放在system32下

#6


这个问题有人回答吗?我也遇到了。
org.jawin.COMException: 8007007f: 
该错误是指未找到dll中的指定函数,同时说明已找到了dll文件。
如果是org.jawin.COMException: 8007007e: 错误的话,则说明未找到dll文件

请大家看看我的代码,帮我分析一下:
import java.io.ByteArrayInputStream;
import org.jawin.COMException;
import org.jawin.FuncPtr;
import org.jawin.ReturnFlags;
import org.jawin.io.LittleEndianInputStream;
import org.jawin.io.LittleEndianOutputStream;
import org.jawin.io.NakedByteStream;

public class NativeDll {

public static void main(String[] args) throws Exception {
//代码段1
FuncPtr funcP = new FuncPtr("Printf.dll", "calc");
String marshal = "II:I:L4L4";
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
leos.writeInt(4);
leos.writeInt(3);
byte[] res = funcP.invoke(marshal, 12, nbs, null, ReturnFlags.CHECK_W32);
ByteArrayInputStream bais = new ByteArrayInputStream(res);
LittleEndianInputStream leis = new LittleEndianInputStream(bais);
int result = leis.readInt();
System.out.println(result);
//代码段2
// FuncPtr funcP = new FuncPtr("USER32.DLL", "MessageBoxW");
// NakedByteStream nbs = new NakedByteStream();
// LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
// leos.writeInt(0);
// leos.writeStringUnicode("Google的浏览器和云计算在忽悠谁?");
// leos.writeStringUnicode("Jawin窗口标题");
// leos.writeInt(0);
// byte[] res = funcP.invoke("IGGI:I:", 16, nbs, null, ReturnFlags.CHECK_FALSE);
// ByteArrayInputStream bais = new ByteArrayInputStream(res);
// LittleEndianInputStream leis = new LittleEndianInputStream(bais);
// int result = leis.readInt(); // the out param
// System.out.println(result);
}
}
其中将代码段1注释掉代码段2恢复时,程序运行正常,这说明我的jawin工程搭建没有问题;
将代码段1恢复代码段2注释掉时,程序运行第一行
"FuncPtr funcP = new FuncPtr("Printf.dll", "calc");"时就报8007007f错误;
我试过很多次,未果,在网上也没找着相关的解决办法。
是不是用jawin不能用来调用自定义的DLL呀?
我想应该不甚于吧。
请大家多多关注JAVA在这方面的应用,
同时也请高手指点指点!
我们真的很需要你们的帮助!
先谢谢啦!
我的邮箱:wolfware@yeah.net
我的MSN:hefusheng@hotmain.com,请附言:jawin

#7


我也遇到这些问题了,,始终没有解决--那为技术高手指点下,分享下经验--谢谢!!!!!!!!!!

#8


org.jawin.COMException: 8007007f: 的问题我解决了,是因为自己做的dll是VC做的,函数名称后面要加"@n"即可,如函数的参数有k个,则n=k*4,如没有参数n=0,2个参数n=8,4个参数n=16;
如下:
   FuncPtr funcP = new FuncPtr("Printf.dll", "calc@16");

#9


回复于:2010-10-21 15:14:07org.jawin.COMException: 8007007f: 的问题我解决了,是因为自己做的dll是VC做的,函数名称后面要加"@n"即可,如函数的参数有k个,则n=k*4,如没有参数n=0,2个参数n=8,4个参数n=16;
如下:
  FuncPtr funcP = new FuncPtr("Printf.dll", "calc@16");
 
 
我得加上@4也不行啊。

#10


人才,用extern "C" 生成标准dll