Commonly used is jni, jnative (based on jni encapsulates its own jar package) Note: Java calls dll, and the corresponding processing must be done in the dll. Columns such as: The method name must be _java_package_class name_method name
Calling dll steps using JNI
Create a new Java project and put the dll file into src
Configure the native directory under jre, point to src
Project jdk must not use the eclipse-owned JDK path.
Create new directories and classes in the order of directory in the dll
Declare the same method as in the dll, add the native keyword before the method (note the parameter type)
Write in static blocks of the code (no suffix):
static {System.loadLibrary("testDll");} Then write the main method and you can call it. If there is an error, please pay attention to the error message, and the dependency dll file may be missing.
Simple encapsulation of JNI
Simple encapsulation of a class that calls a dll
The code can be downloaded in resource sharing, my code
Call code (mainly the static block code has changed), the DllUtil code is downloaded in the share
static {try {DllUtil.extractFromJar("testDll.dll", "testDll.dll", System.getProperty("java.io.tmpdir"));System.load(System.getProperty("java.io.tmpdir") + "//testDll.dll");System.out.println("load testDll.dll success!!");} catch (Exception e) {System.out.println("testDll.dll error:" + e.getMessage());}}The above is the entire content of this article. For more content, you can search on Wulin.com. Thank you for your support.