Kohsuke Kawaguchi: Historically, JNI has been the only option to invoke native libraries. The problem with calling native libraries with JNI is that, for every method, you need to write a java method declaration, and then a bit of native code to do the parameter conversion. This makes it difficult to casually call into native libraries, because you'd have to write another native library just for JNI handling.
NLink overcomes this problem by providing a general-purpose method invocation converter driven by annotation. With NLink, calling a native library is as easy as [...]:
This is just what I asked for 104 days ago. And it works too!
[weiqi@gao]$ cat User32.java
import nlink.win32.*;
@DllClass
interface User32 {
@DllMethod
int MessageBox(int hWnd, String text, String caption, int type);
}
[weiqi@gao]$ cat Main.java
import nlink.win32.*;
public class Main {
public static void main(String[] args) {
User32 proxy = NLink.create(User32.class);
int result = proxy.MessageBox(0/*NULL*/, "Hello, World!", "Hello", 0);
}
}
[weiqi@gao]$ javac Main.java
[weiqi@gao]$ java Main