Java calling dll several ways to summarize

Source: Internet
Author: User

The most common is jni,jnative (the package of your jar based on JNI)
Note: Java invokes the DLL, which must be handled in the DLL. Columns such as: Method name must be _java_ package Name _ Class Name _ Method name use JNI Invoke DLL step to create a new Java project, put DLL file under SRC Configuration Change Project environment JRE under native directory, point to SRC The project JDK must not be brought with Eclipse, using its own installed JDK path to create a new directory and class declaration in the directory order in the DLL in the same way as in a DLL, by adding the native keyword (note parameter type) to the code static block (do not suffix):

static {
    system.loadlibrary ("Testdll");
}
Then write the main method to invoke the. If there is an error, pay attention to observe the error information, may be missing dependent DLL file simple encapsulation Jni Simple Package a calling DLL class code can be shared in the resource, my code download the calling code (mainly static block code changed), Dllutil this piece of code in the share download
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 ());
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.