这是我的一个运行示例DLLService
:
import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
public class DLLService {
public DLLService() throws Exception {
System.out.println("version = " + version() + "\n");
testEvaluate();
}
public void testEvaluate() {
System.out.println(this.loadFile("file", 1));
int[] barre = new int[] {0, 1, 2, 3, 4};
int[] result = new int[]{};
evaluateParty(barre.length, barre, result, 1);
System.out.println(result);
}
public int version() {
return GDLL.INSTANCE.LireNoVersion();
}
public int loadFile(String tslName, int pdwNoSess) {
return GDLL.INSTANCE.ChargerFichier();
}
public interface GDLL extends StdCallLibrary {
GDLL INSTANCE = (GDLL) Native.loadLibrary("tsr32_mini", GDLL.class);
int LireNoVersion();
int ChargerFichier();
}
}
函数没有问题,version()
但没有loadFile(...)
,我有一个例外:
线程“主”中的异常java.lang.UnsatisfiedLinkError:查找函数'EvaluerPartie'时出错:
在com.sun.jna.Function。(Function.java:212)在com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:541)在com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:518)位于com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:504)位于com.sun.jna.Library $ Handler.invoke(Library.java:220)位于com.sun.proxy。$ Proxy0.EvaluerPartie(未知源) )位于DLLService.evaluateParty(DLLService.java:29)于DLLService.testEvaluate(DLLService.java:16)于DLLService。(DLLService.java:9)于ProblemsIsolator.main(ProblemsIsolator.java:53)
我已经搜索了,但没有找到任何有效的方法(更改类型,参数,名称等)。下面是函数L的原型:DWORD ChargerFichier (LPSTR chNom, DWORD *pdwNoSess)
。
编辑:即使使用名称映射器后,同样的错误;它LireVersion
仅适用于:
public void testFunctionMapper() throws Exception {
FunctionMapper mapper = StdCallLibrary.FUNCTION_MAPPER;
NativeLibrary lib = NativeLibrary.getInstance("tsr32_mini");
Method[] methods = {
GDLL.class.getMethod("LireNoVersion",
new Class[] { String.class, int.class }),
GDLL.class.getMethod("ChargerFichier",
new Class[] { String.class, int.class }),
};
for (int i=0;i < methods.length;i++) {
String name = mapper.getFunctionName(lib, methods[i]);
lib.getFunction(name, StdCallLibrary.STDCALL_CONVENTION).getName();
}
}
而且,一个依赖项工作者向我很好地介绍了这些方法。
好像在该链接中起作用:如何获得对DLL的Java JNA调用以获取参数中返回的数据?,我可以看到您对的定义ChargerFichier
缺少参数。
也许定义应该是这样的:
int ChargerFichier(PointerByReference chNom, IntByReference pdwNoSess);
也许此链接也可以为您提供帮助:http : //www.viaboxx.de/code/java-interoperation-with-a-native-dll-using-jna/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句