Java calls c Functions

Source: Internet
Author: User

 

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)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.