The first step: declaring the local variable
<CCID_NOBR>
<CCID_CODE> For example: Class nativehello{public native void Nativehelloworld (); static{system.loodlibrary (" Nativetest ");//Call NativeTest.dll library file}}</ccid_code>
</CCID_NOBR>
Step two: Generate header files
First compile the Nativehello.java with Javac, then use Javah to generate the header files of C. h files
Step three: Generate Root files
Commands are as follows: Javah-stubs Nativehello (Generate NATIVEHELLO.C file)
Step Fourth: Write a C program (this assumes the file name is nativetest.c)
<CCID_NOBR>
<CCID_CODE> #include <stdio.h> #include <nativehello.h>//refers to the #include <stubpreamble.h of the. h file generated in the second step. >//refers to the file void Nativehello_nativehelloworld (struct Hnativehello *this) {...} under the JDK's include. /</ccid_code>
</CCID_NOBR>
* Function name Nativehello_nativehelloworld cannot be arbitrarily specified, can be found in the header file generated by Javah, or you may also use the following method name: Class Name _ local method name (struct H class name *this) * *
Step Fifth: Compile the DLL file
Compile nativetest.c and nativehello.c into a DLL library file with the same name as the file in System.loodlibrary ("Nativetest")
Finally, the test method, the source file is as follows:
<CCID_NOBR>
<ccid_code>class usenative{public static void Main (String []args) {Nativehello nh=new Nativehello (); Nh.nativehelloworld (); }}</ccid_code>
</CCID_NOBR>