Step 1: Disclaimer local variables
For example: Class nativehello {
Public native void nativehelloWorld ();
STATIC {
System.loodlibrary ("nativetest"); // Call Nativeest.dll library file
}
}
Step 2: Generate head file
First compile nativehello.java with Javac, then generate C's header files .h files with Javah.h file
Step 3: Generate root files
The command is as follows: javah -stubs nativehello (generated nativehello.c file)
Step 4: Write a C program (assuming the file named nativeest.c here)
#include
#include
#include
Void nativehello_nativehelloworld (struct hnativehello * this) {
.........
} /
* Function name nativeHello_nativeHelloWorld cannot be arbitrarily specified, can be found in the header file generated from Javah, or name the following method: Class name _ local party name (Struct H name * this) * /
Step 5: Compile DLL files
Compile Nativeest.c and NativeHello.c into DLL library files, file names are the same as the file name in System.Loodlibrary ("Nativeest")
Finally, let's talk about the test method, the source file is as follows:
Class option {
Public static void main (String [] args) {
Nativehello nh = new nativehello ();
nh.nativeHelloWorld ();
}
}
Http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/javah.html