【发布时间】:2012-01-31 11:30:07
【问题描述】:
已编辑问题:
尝试通过 JNA 使用来自 Java 的 .dll 文件。我设法:
将 .dll 添加到系统库 - System.loadLibrary("NativeLibrary");
创建了一个 NativeInterface 来映射 .dll/.h 文件中的函数:
public interface NativeInterface extends Library, StdCallLibrary {
public int methodA(packageURL.NativeInterface.typeDefName n);
public int methodB();
public static class typeDefName implements Structure.ByReference{
public typeDefName(short s) {}
}
}
将映射添加到我的函数名称,因为它在 .dll 中的名称是“损坏的” - 使用 Dependency Walker 发现了这一点
Map options = new HashMap();
options.
put(
Library.OPTION_FUNCTION_MAPPER,
new Mapper() {
public String getFunctionName(NativeLibrary library, Method method) {
return super.getFunctionName(library, method);
}
}
);
与:
class Mapper implements FunctionMapper{
public String getFunctionName(NativeLibrary library, Method method) {
return "?" + method.getName() + "@@YAHPAEIPAPAXFPAUtypeDefName@@@Z";
}
}
现在(我不确定)是如何创建 typeDefName 的对象以传递给方法 A
【问题讨论】:
标签: java c dll java-native-interface native