Search code examples
javajna

Options in Native.loadLibrary


I have been working on JNA for some time now. But there is one thing, I haven't understood. For example, while loading a library:

Map<String, Integer> options = new HashMap<String, Integer>();
options.put(Library.OPTION_CALLING_CONVENTION, StdCallLibrary.STDCALL_CONVENTION);
this.EDSDK = (EdSdkLibrary) Native.loadLibrary("EDSDK/dll/EDSDK.dll", EdSdkLibrary.class, options);

What exactly is the options above?

The api says:

public static Object loadLibrary(String name, Class interfaceClass, Map options)

Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library. If no library options are detected the map is interpreted as a map of Java method names to native function names. If name is null, attempts to map onto the current process.

Above what does map of options for the library mean?


Solution

  • It's a map that holds the options for the library. One such option is a function mapper. Below you can find an example:

        System.setProperty("jna.library.path","SiUSBXp.dll");
        HashMap<String, StdCallFunctionMapper> optionMap = new HashMap<String,    StdCallFunctionMapper>();
        StdCallFunctionMapper myMapper = new StdCallFunctionMapper();
        optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper);
        INSTANCE = (SiUSBXp) Native.loadLibrary("SiUSBXp", SiUSBXp.class, optionMap);