best answer
1. compile the example document public class testnative {private native static int max (int A, int B); public static void main (string [] ARGs) {system. out. println (max (4, 5);} static {system. loadlibrary ("vcdll") ;}} you can specify the DLL file name in loadlibrary. you only need to rename the dynamic link library to this string. the source of native functions is the dynamic link library. 2. after preparing for this step, use javac testnative. java generates testnative. class. check syntax. 3. after the syntax check is passed, use javah testnative to generate testnative. h c ++ header file. 4. use VC ++ 6.0 to create a DLL file: <1> msdev-> New-> Project-> Win32 dynamic-Link Library <2> enter project name (e.g. vcdll) <3> choose "an empty DLL project"-> finish <4> Add testnative. H and JNI under JDK. add H and jni_md.h to the project. <5> Create a c ++ file, implements the native method. as follows: // testnative. CPP # include "testnative. H "jniexport jint jnicall java_testnative_max (jnienv * a, jclass B, jint X, jint y) {return x> Y? X: Y;} remarks: JNI. h Generally, JDK/include/can be copied to the include directory under the VC installation directory first. once and for all, JNI technology can be easily used in the future. b. the Java and VC interfaces must be considered for all data types. use jint jstring and so on. c Function Name and automatically generated. the consistency specified in the H file. the naming rule is: Java _ use class_method name 6. compile the VC ++ project. if no error occurs, the dynamic link library is generated. set the dynamic Connection Library vcdll. DLL to testnative. java directory. 7. run Java testnative. OK :-)