JNI Java C + + Dynamic library function, multi-value callback and garbled problem

Source: Internet
Author: User

One, JNI Java tune C + + dynamic library function problem
1. Multi-Parameter callback
2. Parameter passing is garbled

Second, to solve
1. Using the byte[] array in C + +, the generated header file will become the Jbytearray type
For example, in Java parameters: Byte[]account, the parameters in the header file become Jbytearray account,
After modifying the value of the account through C + +, Java wants to get the value, directly using the
jbyte* Jbaccount = (env)->getbytearrayelements (env, account, 0);
char* Szaccount = (char*) jbaccount;
The address of the pointer is not the address of the account, and the value is finally assigned.
Env->setbytearrayregion (Account,0,strlen (szaccount), jbyte* jbaccount);

2.string.getbytes () The resulting byte array is passed into C + +, there will be extra garbled characters at the end of the string.
The workaround is to pass the length of the array to C + + when passing in a byte array,
Make the accepted array strbuff[length]= ' \ n '; solve the problem

JNI Java C + + Dynamic library function, multi-value callback and garbled problem

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.