JNA
0x01 What Is JNA
0x02 Best Pratice
cmake_minimum_required(VERSION 3.29)
project(myLib)
set(CMAKE_CXX_STANDARD 20)
add_library(myLib SHARED library.cpp)
Last updated
cmake_minimum_required(VERSION 3.29)
project(myLib)
set(CMAKE_CXX_STANDARD 20)
add_library(myLib SHARED library.cpp)
Last updated
#ifndef MYLIB_LIBRARY_H
#define MYLIB_LIBRARY_H
#ifdef __cplusplus
extern "C"
{
int max(int, int);
}
#endif
#endif#include "library.h"
int max(int num1, int num2) {
return num1 > num2 ? num1 : num2;
}<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.10.0</version>
</dependency>import com.sun.jna.Library;
import com.sun.jna.Native;
public interface JnaLibrary extends Library {
JnaLibrary INSTANCE = Native.load("myLib", JnaLibrary.class);
int max(int a, int b);
}int max = JnaLibrary.INSTANCE.max(125, 135);
System.out.println(max); // 135