Recently, the company needs encryption on a card-building project, so it needs to call the C function in Java. So I studied it and referred to some examples on the Internet, I tried it myself and gave an example as follows:
Java class
Package com. lzg;
Public class test {static {system. loadlibrary ("swdes");} public native static string gencvv (string pscardno, string javasxpiry, string psservicecode ); /***** @ Param ARGs * @ author lzg * @ time 3:57:26 */public static void main (string [] ARGs) {// todo auto-generated method stub gencvv ("123", "1312", "1234 ");}}
Then you need to compile it into a class
Javac test. Java
Then compile it as a. h file.
The class path of the javah-classpath project is com. lzg. Test.
Then you can get. h file, you need. the H file is handed over to C's students for development and then generated. so or. DLL file, which you put into Java for calling (to be improved)