Set<type>Field Routines - SetShortField
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()
. (SetShortField)
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
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-2b Set<type>Field Family of Accessor Routines
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 - SetShortField
JNIEXPORT jint JNICALL Java_org_mangler_VentriloInterface_getevent(JNIEnv* env, jobject obj, jobject eventdata) {
v3_event *ev = v3_get_event(V3_BLOCK);
if(ev != NULL) {
jclass event_class = (*env)->GetObjectClass(env, eventdata);
// Event type.
jfieldID type_field = (*env)->GetFieldID(env, event_class, "type", "S");
(*env)->SetShortField(
env,
eventdata,
type_field,
1234
);
// Get PCM class.
jfieldID pcm_field = (*env)->GetFieldID(env, event_class, "pcm", "Lorg/mangler/VentriloEventData$_pcm;");
jobject pcm =
(*env)->GetObjectField(
env,
eventdata,
pcm_field
);
jclass pcm_class = (*env)->GetObjectClass(env, pcm);
// Set PCM fields.
jfieldID pcm_length_field = (*env)->GetFieldID(env, pcm_class, "length", "I");
(*env)->SetIntField(
env,
pcm,
pcm_length_field,
1337
);
free(ev);
}
return 0;
}