How Java invokes dll files
This article mainly introduces how to call the dll file by Java, which is very detailed and has certain reference value. Friends who are interested must finish it!
Java calls the dll file
Recently, according to C++ to do a picture quality inspection project, currently need to be called in java, so first generate dll file on C++, and then call dll file based on java to achieve the function.
Environment
C++:VS2017 (it was fatal to configure opencv before)
Java:idea2020+jdk1.8 .
Note: be careful when installing jdk, the path path is easy to edit, do not create it, it will be overwritten.
Next, let's go to the text.
1. To create a Java project, suppose you define the HelloWorld function, where "winproject1" is the dll file to be called later, now enter cmd and cd to the current directory, and then javah-jni HelloWorld.HelloWorld, which will generate a HelloWorld_HelloWorld.h under the directory.
Later, you need to move this header file to the include in the previous installation jdk directory, such as: DJava% your path%\ Java\ include.
two。 Open vs2017, create a new console project, and then configure the path where the project contains the directory, adding the following two paths, and the insurance point can add these paths to the additional directory.
Write the code in the header file above in vs2017:
JNIEXPORT void JNICALL Java_HelloWorld_HelloWorld_sayHello (JNIEnv *, jobject, jstring, jstring) {cout