使用StdCallFunctionMapper重命名JNA中的DLL函数 [英] renaming DLL functions in JNA using StdCallFunctionMapper

查看:798
本文介绍了使用StdCallFunctionMapper重命名JNA中的DLL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows中使用JNA和DLL,到目前为止,我能够成功调用一个名为 c_aa_find_devices()的函数。但是所有的功能都是从 c_aa 开始,我想将其重命名为 find_devices()



从我收集的方式来做,这是与 StdCallFunctionMapper ,但是我在一个例子中找不到如何使用它的文档(即如何映射一个DLL通过名称或按顺序到包装的Java库接口中的所需名称进行功能)。任何关于文档位置的建议?

解决方案

使用StdCallMapper不会做得好 - 它应该映射werid windows std lib将嵌入的总字节长度嵌入作为名称的一部分的名称。因为它只是为了std lib(只是猜测,但99%你的功能不是这样)。



如果您的DLL在所有功能上使用一些常用的前缀,您只需使用以下类似的东西:

  class Mapper实现FunctionMapper {
public String getFunctionName(NativeLibrary library,Method method){
return GenieConnector.FUNCTION_PREFIX + method.getName();
}
}

其中 GenieConnector.FUNCTION_PREFIX 是共同的前缀。请记住,我实现 FunctionMapper ,不扩展 StdCallMapper


I'm trying to use JNA with a DLL in Windows, so far I was able to successfully call a function called c_aa_find_devices(). But all the functions start with c_aa and I would like to rename it to find_devices().

From what I gather the way to do this is with StdCallFunctionMapper but I can't find the documentation of how to use it in an example (i.e. how to map a DLL function by name or by ordinal to a desired name in the wrapped Java library interface). Any suggestions on where the docs are?

解决方案

Using StdCallMapper won't do good - it is supposed to map werid windows std lib names that have embedded total byte lenght of parameters embedded as part of the name. Since it is done to std lib only (just guessing on that, but 99% you'r functions are not the case).

If your dll uses some common prefix on all functions you need just to use something like:

class Mapper implements FunctionMapper{
    public String getFunctionName(NativeLibrary library, Method method) {
       return GenieConnector.FUNCTION_PREFIX + method.getName();
    }
}

Where GenieConnector.FUNCTION_PREFIX is that common prefix. Bear in mind that i implement FunctionMapper, not extend StdCallMapper

这篇关于使用StdCallFunctionMapper重命名JNA中的DLL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆