You can declare both of them with StdCallLibrary / StdCallCallback, but the behavior may not be defined on all platforms. The option is ignored on platforms that do not support an alternative calling convention (that's all except win32 at the moment), but was not necessarily tested on all platforms.
This is the preferred definition that defines the stdcall library for windows only.
interface MyLibrary extends Library { interface MyCallback extends Callback { public void invoke(); } void callbackFunction(MyCallback cb); MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary("mylib", Platform.isWindows() ? MyWin32Library.class : MyLibrary.class); } interface MyWin32Library extends MyLibrary, StdCallLibrary { interface MyStdCallCallback extends MyCallback, StdCallCallback {} void callbackFunction(MyStdCallCallback cb); }
If you just target Linux and windows, then one interface might be enough (I would recommend checking this out though):
interface MyLibrary extends StdCallLibrary { interface MyCallback extends StdCallCallback { public void invoke(); } void callbackFunction(MyCallback cb); MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary("mylib", MyLibrary.class); }
source share