On Dec 12, 2007, at 8:31 AM, Nicolas Vienne wrote:
Timothy Wall <twalljava@...> writes:
You have two options.
1) pass a StdCallFunctionMapper to Native.loadLibrary as an option.
This will convert "add" to "add <at> 8", which is the default symbol
generated for your add function with the stdcall convention.
2) tell your compiler/linker to generate undecorated symbols. With
gcc, this is "-Wl,--add-stdcall-alias".
Oops, this gcc option tells gcc to *add* decorated symbols. If you
leave it off, you get only undecorated symbols. MSVC requires you to
futz with a DEF file to get undecorated symbols.
In addition, make sure you have
extern "C" int add(int, int);
^^^^^^^^^^
as the function declaration if compiling with a C++ compiler.
Otherwise the compiler mangles the name to include type information,
and JNA does not automatically handle that.
Ok, I've done what you said. The symbol i actually have in the DLL
is "_add@8".
I tried (again) to use StdCallFunctionMapper but it doesn't work :(
Map hm = new HashMap<String, Object>();
hm.put(DllFunction.OPTION_FUNCTION_MAPPER, new
StdCallFunctionMapper());
DllFunction myDll = (DllFunction) Native.loadLibrary("DllTest",
DllFunction.class, hm);
System.out.println(myDll.add(12,30));
[The same result is obtained with DllFunction.FUNCTION_MAPPER and my
interface extends StdCallInterface]
1. What is wrong in my use of the function mapper ?
2. Will it work (I'm optimistic) with function whose symbol ends with
@12 or @20 ?
1. That should work, and does work within JNA's own unit tests (see
W32StdCallTest). Make sure you're doing a clean build.
2. Yes, it will work with any function callable from JNA