import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class JnaTest
{
//继承Library,用于加载库文件
public interface CLibrary extends Library
{
CLibrary INSTANCE = (CLibrary) Native.loadLibrary(
(Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
// 声明一个跟C语言的printf()一样的方法,
void printf(String format, Object... args);
}
public interface TestLibrary extends Library
{
TestLibrary INSTANCE = (TestLibrary) Native.loadLibrary("jnatest", TestLibrary.class);
void test_jna();
}
public static void main(String[] args)
{
//调用
CLibrary.INSTANCE.printf("From JAVA To C, year=%d\n", 2022);
TestLibrary.INSTANCE.test_jna();
}
}