If this char* is a generic string, it can be passed back as a string. If it is a buffer containing ' bytearray ', it is best to spread out as a copy, because it can be set to the length, if the copy to a string, may be truncated.
There are two ways to pass the resulting data:
one is the direct new byte array in Jni, and then the call function (*env)->setbytearrayregion (env, ByteArray, 0, Len, buffer); Copy the value of buffer to ByteArray, and the function will return directly to ByteArray.
one is the return error number, the data is passed as a parameter, but the basic data type of Java is a value, and the object is a passing reference, so the byte array that needs to be outgoing is wrapped with a class, as follows:
class Retobj
{
Public byte[] ByteArray;
}
This object is retobj out as the parameter of the function, and the byte array in the Retobj is assigned to be easily outgoing through the following function. The code is as follows:
Jclass CLS;
Jfieldid FID;
Jbytearray ByteArray;
ByteArray = (*env)->newbytearray (Env,len);
(*env)->setbytearrayregion (env, ByteArray, 0, Len, buffer);
cls = (*env)->getobjectclass (env, retobj);
FID = (*env)->getfieldid (env, CLS, "Retbytes", "[B"]);
(*env)->setobjectfield (env, retobj, FID, ByteArray);
End.