Saturday, April 20, 2013

jni jnienv SetByteField example c c++ java


Set<type>Field Routines - SetByteField


void Set<type>Field(JNIEnv *env, jobject obj, jfieldID fieldID, NativeType value);

This family of accessor routines sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling GetFieldID(). (SetByteField)

The following table describes the Set<type>Field routine name and value type. You should replace type in Set<type>Field with the Java type of the field, or use one of the actual routine names from the table, and replace NativeType with the corresponding native type for that routine.

Table 4-2a Set<type>Field Family of Accessor Routines

Set<type>Field Routine

Native Type

SetObjectField()

jobject

SetBooleanField()


jboolean

SetByteField()

jbyte

SetCharField()

jchar

SetShortField()

jshort

SetIntField()

jint

SetLongField()

jlong

SetFloatField()

jfloat

SetDoubleField()

jdouble
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-2b Set<type>Field Family of Accessor Routines

Set<type>Field Routine

Index

SetObjectField()
104

SetBooleanField()

105

SetByteField()
106

SetCharField()
107

SetShortField()
108

SetIntField()
109

SetLongField()
110

SetFloatField()
111

SetDoubleField()
112
PARAMETERS:

env: the JNI interface pointer.

obj: a Java object (must not be NULL).

fieldID: a valid field ID.

value: the new value of the field.
Example - SetByteField

native void nativeModifyByte(Byte b);

JNIEXPORT void JNICALL Java_nativeModifyByte(JNIEnv * env, jobject o, jobject b) {
   jclass c = (*env)->GetObjectClass(env, b);
   jfieldID fid = (*env)->GetFieldID(env, c, "value", "B");
   jbyte oldVal = (*env)->GetByteField(env, b, fid);
   (*env)->SetByteField(env, b, fid, 42);
}