renaming DLL functions in JNA using StdCallFunctionMapper

后端 未结 4 477
梦谈多话
梦谈多话 2020-12-30 15:18

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

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 16:15

    From the documentation you need to provide a FunctionMapper in the original call to loadLibrary that converts the name. However you also need to keep the standard call mapping so try something like the following:

    Map options = new HashMap();
    
    options.
        put(
            Library.OPTION_FUNCTION_MAPPER, 
            new StdCallFunctionWrapper() {
                public String getFunctionName(NativeLibrary library, Method method) {
                    if (method.getName().equals("findDevices") 
                        method.setName("c_aa_find_devices");
                    // do any others
                    return super.getFunctionName(library, method);
                }
            }
        );
    
    Native.loadLibrary(..., ..., options);
    

提交回复
热议问题