Article Directory
I. JNIEXPORT and macro definitions JNICALL
JNIEXPORT and JNICALL two macros are defined in the JNI:
① Windows platform macro definitions:
#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_
#define JNIEXPORT __declspec(dllexport)
#define JNIIMPORT __declspec(dllimport)
#define JNICALL __stdcall
typedef long jint;
typedef __int64 jlong;
typedef signed char jbyte;
#endif /* !_JAVASOFT_JNI_MD_H_ */
② Linux platform macro definitions:
#define JNIIMPORT
#define JNIEXPORT __attribute__ ((visibility ("default")))
#define JNICALL
JNIEXPORT in Windows and Linux respectively corresponding to different macro definition;
. 2 JNIEXPORT role of macro definitions:
If you need to generate Windows DLL, and requires the use of dynamic libraries to other projects, need to add a special logo in front of the method, the method of the DLL dynamic library defined in order to call an external program code;
① Windows platform: you need to return method added __declspec (dllexport) before the value of the identification;
② Linux platform: you need to join before the method returns the value attribute ((visibility ( "default"))) identity;
The statement of the role is to ensure that the method stated in this dynamic library can be invoked in other projects;
. 3 JNICALL role of macro definitions:
Windows JNICALL ①: JNICALL is defined as __stdcall, __stdcall calling convention a functional parameters when calling functions in Windows, the parameters of the function is stored in the form of a stack, the stack element is LIFO, __stdcall It represents the parameter is saved from right to left;
__stdcall function is used to define the rules of the stack (from right to left), and stack cleanup rules;
Linux JNICALL ②: JNICALL not defined directly home empty; in Linux can not write JNIEXPORT and JNICALL macros;
II. JNIEXPORT and JNICALL macro definition Description (Windows platform)
. 1 Windows platform macro definition Description:
① JNIEXPORT macro definitions: Windows platform definition "#define JNIEXPORT __declspec (dllexport)" , the compiler, it uses "__declspec (dllexport)" instead of JNIEXPORT;
② JNICALL macro definitions: Windows platform macro definition "#define JNICALL __stdcall" , at compile time, use the "__stdcall" instead of JNICALL;
. 2 JNIEXPORT and JNICALL macro substitution analysis (Windows platform):
① using the original method of JNIEXPORT and JNICALL:
extern "C"
JNIEXPORT void JNICALL
Java_kim_hsl_jni_Main_jniTest
(JNIEnv* env, jobject instance, jint i, jstring s_) {
}
② compiled code of Chengzhong Hong substitution:
extern "C"
__declspec(dllexport) void __stdcall
Java_kim_hsl_jni_Main_jniTest
(JNIEnv* env, jobject instance, jint i, jstring s_) {
}
III. JNIEXPORT and JNICALL macro definition description (Linux platform)
. 1 Linux platform macro definition Description:
① JNIEXPORT macro definitions: Linux platform defines
#define JNIEXPORT attribute ((visibility ( "default"))) ,
the compiler, it uses "__declspec (dllexport)" instead of JNIEXPORT;
② JNICALL macro definitions: Linux platform, the macro definition is empty;
. 2 JNIEXPORT and JNICALL macro substitution analysis (Linux platform):
① using the original method of JNIEXPORT and JNICALL:
extern "C"
JNIEXPORT void JNICALL
Java_kim_hsl_jni_Main_jniTest
(JNIEnv* env, jobject instance, jint i, jstring s_) {
}
② compiled code of Chengzhong Hong substitution:
extern "C"
__attribute__ ((visibility ("default")))
void
Java_kim_hsl_jni_Main_jniTest
(JNIEnv* env, jobject instance, jint i, jstring s_) {
}