jna예제
// jna-4.1.0.jar 와 같이 jna 자르파일이 필요함.
// jna는 자바 네이티브 액서스로 jni(자바 네이티브 인터페이스)보다 좀 더 접근이 용이함
package com;
import com.sun.jna.*;
interface MyUser32 extends Library {
public int MessageBoxA(int handle, String message, String title, int type);
}
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
String mytext = “Hello World!”;
String mytitle = “Title bar”;
String libName = “c”;
if (System.getProperty(“os.name”).contains(“Windows”)) {
libName = “user32”;
}
MyUser32 user32 = (MyUser32) Native.loadLibrary(libName, MyUser32.class);
user32.MessageBoxA(0, mytext, mytitle, 0);
}
}
//Dll 함수 API을 보고 파라메터에 해당하는 인자를 인터페이스로 만들어 사용하면 됨