#define JINT "I"
#define JLONG "J"
#define JFLOAT "F"
#define JSTR "Ljava/lang/String;"
#define JBOOL "Z"
#define JBYTES "[B"
///获取变量ID
jfieldID GetFieldID_(int line,
JNIEnv* jni,
jclass c,
const char* name,
const char* signature);
///获取变量ID
jfieldID GetFieldID_(int line,
JNIEnv* jni,
jclass c,
const char* name,
const char* signature) {
jfieldID f = jni->GetFieldID(c, name, signature);
CHECK_EXCEPTION(jni) << "error during GetFieldID"
<< " line: " << line;
CHECK(f) << name << ", " << signature << " line: " << line;
return f;
}
///获取变量ID
#define _GetFieldID(_jni_, _c_, _name_, _signature_) \
GetFieldID_(__LINE__, _jni_, _c_, _name_, _signature_)
///获取整型变量
jint GetIntField_(int line,
JNIEnv* jni,
jobject object,
jclass cls,
const char* name);
///获取整型变量
jint GetIntField_(int line,
JNIEnv* jni,
jobject object,
jclass cls,
const char* name) {
// 重要的是这一句, 其他类型的调用其他的名称,如:GetLongField....
jint i = jni->GetIntField(object, _GetFieldID(jni, cls, name, JINT));
CHECK_EXCEPTION(jni) << "error during GetIntField"
<< " line: " << line;
return i;
}
#define _GetIntField(_jni_, _obj_, _cls_, _name_) \
GetIntField_(__LINE__, _jni_, _obj_, _cls_, _name_)
jint sn = _GetIntField(env, msg, cls, "sn");
网友评论