English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The commonly used ones are JNI, jnative (based on JNI, it has encapsulated its own jar package). Note: When Java calls dll, the corresponding processing must be done in the dll. For example, the method name must be _java_package_name_class_name_method_name
Steps to call dll using JNI
Create a new Java project and place the dll file in the src directory
Configure the native directory under the jre of this project environment to point to src
The JDK for the project must not use the JDK path provided by Eclipse, use the one you have installed.
Create directories and classes in order according to the directory sequence in the dll
Declare the method like in the dll, add the native keyword before the method (note the parameter type)
Write in the static block (do not add suffix):
static { System.loadLibrary("testDll"); }
After writing the main method, you can call it. If there are errors, pay attention to the error messages, and it may be missing the dependency dll file
Encapsulate JNI simply
Encapsulate a class that calls a dll simply
The code can be shared, and you can download my code from the resource sharing section
The calling code (mainly the static block code has changed), the DllUtil code in the shared section can be downloaded
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()); } }
That's all for the content of this article. For more content, you can search for Naoa Tutorial, thank you for your support.
Statement: The content of this article is from the network, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, does not undergo artificial editing, and does not bear relevant legal liabilities. If you find content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.