The Artima Developer Community
Sponsored Link

Java Buzz Forum
Ah, NLink!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Ah, NLink! Posted: Feb 12, 2007 2:38 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Ah, NLink!
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

(Via Cafe au Lait)

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

Read: Ah, NLink!

Topic: links for 2007-02-08 Previous Topic   Next Topic Topic: Java 7 Roundup (Feb 7th)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use