Edited Question:
Trying to use a .dll file from Java using JNA. I’ve managed to:
Add the .dll to the System Library – System.loadLibrary(“NativeLibrary”);
Created a a NativeInterface to map the functions in the .dll/.h file:
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) {}
}
}
Added the mapping to my function name because its name in the .dll is “mangled” – Found this out using 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);
}
}
);
AND:
class Mapper implements FunctionMapper{
public String getFunctionName(NativeLibrary library, Method method) {
return "?" + method.getName() + "@@YAHPAEIPAPAXFPAUtypeDefName@@@Z";
}
}
Now (What I’m not sure of) Is how to create an Object of typeDefName to pass into Method A
If your goal is just to use an existing DLL from Java, you can use JNA
without doing any native programming at all. JNA accesses the methods of third-party shared libraries dynamically. You could use the library directly or use JNA to write a convenient wrapper entirely in Java.
When you click the link, be sure to scroll down — there’s lots of documentation and stuff, but the top of the page is consumed by a file listing so it doesn’t look very useful until you scroll down.