Albert Strasheim wrote:
Hello all
I recently started using JNA and I'm seriously impressed.
I was wondering if JNA has a way to access extern variables in a DLL?
There variables are typically declared as extern __declspec(dllexport)
on Windows and simply as extern on other platforms.
Various C libraries I've encounted make use of these variables as a
way of providing default flags without using a #define (which would
cause the defaults to be compiled into the program linking against the
library, which could lead to problems if the library is upgraded).
At least on linux (and presumably macosx), you can just get the address
of the library variable via NativeLibrary.getFunction:
Pointer p_errno = NativeLibrary.getInstance("c").getFunction("errno")
System.out.println("errno=" + p_errno.getInt(0));
Its not pretty, but it works.
Not sure how or if that would work on windows though.
JNA could presumably encapsulate that via something like:
interface Libc extends Library {
static Libc INSTANCE = ...;
static GlobalVariable<Integer> errno;
}