4 messages in net.java.dev.jna.usersRe: [jna-users] Accessing extern vari...
FromSent OnAttachments
Albert StrasheimAug 21, 2007 10:09 am 
Wayne MeissnerAug 21, 2007 7:53 pm 
Albert StrasheimAug 22, 2007 1:58 am 
Wayne MeissnerAug 22, 2007 2:32 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Accessing extern variables with JNAActions...
From:Wayne Meissner (wmei@gmail.com)
Date:Aug 21, 2007 7:53:26 pm
List:net.java.dev.jna.users

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; }