Reuse C ++ code in Java

Source: Internet
Author: User
There are many development tools, such as Java, C ++, and ,. Net, how to implement it in these different development tools CodeIt becomes an important topic and an important means to increase productivity and reduce project costs. C ++ and. net is better integrated, because it is based on the development platform and Solutions of MS, such as COM, DLL, ActiveX, but Java and C ++ are more troublesome. The following describes how to reuse C ++ code through JNI.
1. Declare the native method in Java
Public class message {
Static {
System. Load ("C: // lib // message. dll ");
}
Public native static Boolean send (string mobile, string text );
}

Among them, the DLL name is equivalent to the DLL generated by C ++, And the send method is the code to be reused in C ++. in Java, you only need to give a declaration, the code is implemented in C ++.

2. Compile the header file
Use the javah command to generate the header files required in C ++, such.
Javah message
Note that message. Class is already used. A message. h file is generated.

3. In C ++.
Open the vc6.0 project, use Wizard to generate a DLL, include the header file generated by javah, and implement the Code to be reused. Generally, you can make a call to the encapsulated class here.

Others:
Java definitions such as Boolean and string all have corresponding conversions in JNI. H, such as jboolean, which can be directly used.
I hope to discuss it with you further.

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.