You have two options.
1) pass a StdCallFunctionMapper to Native.loadLibrary as an option.
This will convert "add" to "add@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".
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.
On Dec 12, 2007, at 5:48 AM, Nicolas Vienne wrote:
Hello everybody,
I have a little problem while trying to use JNA with my own DLL.
I defined the function :
int add(int a, int b)
I tried many mappings (StdCallLibrary, Library, etc ...), for
instance:
public interface DllFunction extends StdCallLibrary {
DllFunction INSTANCE = (DllFunction)Native.loadLibrary("DllTest",
DllFunction.class);
public int add(int a, int b);
}
but every time, the call:
DllFunction.INSTANCE.add(12, 30)
raises an "java.lang.UnsatisfiedLinkError: Cannot locate function
'add'".
I tried also to pass an StdCallFunctionMapper but it fixed nothing.
After taking a look at the dll file with depends i found that the
function
was named "?add@@YAHHH@Z", and thus:
NativeLibrary nl = NativeLibrary.getInstance("DllTest");
Function f = nl.getFunction("?add@@YAHHH@Z");
Object[] a = {12,30};
System.out.println(f.invokeInt( a ));
works fine.
I wonder if there is a way to do it the "right" way ie with the
interface
mapping ?
Thank you for any help !