Libraries compiled with the stdcall convention have decorated
function names (each function name gets "@NNN" appended, where NNN is
the size of the function's argument stack). You need a
FunctionMapper to get the right names (namely, an instance of
StdCallFunctionMapper). You pass this in as an option to
Native.loadLibrary, e.g.
Map options = new HashMap();
options.put(Library.OPTION_FUNCTION_MAPPER, new StdCallFunctionMapper
());
Native.loadLibrary("MyDLL", MyDLL.class, options);
On Oct 18, 2007, at 8:45 PM, Daniele Romagnoli wrote:
Hi List.
I'm a very beginner on JNA :)
I would like to start test it as soon as possible and I have a
really simple question for you.
I have the following C code:
typedef void *MyDriverH; //Handle Type
MyDriverH __declspec(dllexport) __stdcall getDriverByIndex(int
driverIndex);
What I have to do to get a Driver Handler in Java? I'm trying this
solution
public interface MyDLL extends StdCallLibrary{
MyDLL INSTANCE = (MyDLL) Native.loadLibrary("MyDLL",
MyDLL.class , new HashMap() {{ put(OPTION_FUNCTION_MAPPER,
FUNCTION_MAPPER); }});
public static class MyDriverH extends HANDLE {
}
public MyDriverH getDriverByIndex(int driverIndex);
public static class HANDLE extends PointerType {
public HANDLE() {
}
public HANDLE(Pointer p) {
super(p);
}
};
}
Then using this test code:
public class Test {
public static void main(String[]args){
MyDLL lib = MyDLL .INSTANCE;
MyDriverH driver = lib. getDriverByIndex(1);
}
}
But I receive this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot
locate function 'getDriverByIndex'
at com.sun.jna.NativeLibrary.getFunctionAddress
(NativeLibrary.java:219)
at com.sun.jna.Function.<init>(Function.java:141)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:206)
at com.sun.jna.Library$Handler.invoke(Library.java:161)
at $Proxy0.getDriverByIndex(Unknown Source)
at attempt.Test.main(Test.java:9)
Surelly, I'm doing something wrong but I cant figure out what :)
Can someone help me?
Thanks