???????? I have been designed to JNI in the recent project. For VC I am a known semi-solving. JNI is the interface of the Native method, never used it. But I have been touched, but I feel a bit road, IF the JNI problem In the future, I don't dare to conceal my little advancement, and publicly open to the brothers who don't understand.
JNI call DLL is used in JAVA
1? Write an example document
PUBLIC? CLAS? testnative {
??
??prate? native? int? add (int? x, int? y);
??
?? public? static? void? main (string []? args? {
???? Testnative? Hh? =? New? Testnative ();
???? int? r? =? HH.Add (30, 20);
???? system.out.println ("result? =?" R);
??}
?? static? {
???? System.loadLibrary ("DLL_0305");
??}
}
among them
The DLL file name in LoadLibrary can be cascaded. As long as the Dynamic Link Library is changed to this string. The source of the Native function is the dynamic link library.
2. After you are ready, use Javac? Testnative.java to generate .class. Class. Test syntax.
3. After the syntax check, create a .h C header file with Javah? Testnative.
4. Open VC 6.0, New ->? Engineering? ->? Win32? Dynamic-link? Library. Select an empty project in the wizard.
5. • Add the header file that Javah generated to the project? Then? File -> New-> TextFile? Do a .c file yourself. Implement your own Native function. List is as follows:
#include
JNIEXPORT? JINT? JNICALL? JAVA_TESTNATIVE_ADD
?? (JNIENV? * EV,? Jobject? Obj,? Jint? X,? Jint? Y)
{
RETURN? X Y;
}
Remarks:
A? The jni.h is usually in? JDK / INCLUDE /? Can copy it to the include directory in the VC installation directory. One is eternal, and JNI technology can be easily used in the future.
B ?? All data types need to consider the interface issues of Java and VC. Use jint ?? jstring? Et al.
C ?? Function Name and Automatically generated. Hype files specified. Named rules:? Java_ use class _ method name?
6? Compile the project.
?? If there is no error, then generate the dynamic link library success.
? "Copy the dynamic link library to the directory where the testnative.java is located.
7? Run Java? Testnative Look at the results.