文章字数:251,阅读全文大约需要1分钟
java native interface JNA(Java Native Access)框架是一个开源的Java框架,是SUN公司主导开发的,建立在经典的JNI的基础之上的一个框架
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; import com.sun.jna.win32.StdCallLibrary;
public class JNADllCall {
public interface StdCallDll extends StdCallLibrary { StdCallDll INSTANCE = (StdCallDll) Native.loadLibrary("dllName",StdCallDll.class); void printf(String format, Object... args); }
public interface CLibrary extends Library { CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
void printf(String format, Object... args); }
public static void main(String[] args) { StdCallDll.INSTANCE.printf("Hello, World!\n"); CLibrary.INSTANCE.printf("Hello, World\n"); } }
|