Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help on understanding generated JNI header file

I was going through JNI tutorial and I came across below line in generated header file.

JNIEXPORT jbyteArray JNICALL Java_ReadFile_loadFile
(JNIEnv *, jobject, jstring);

I can understand the meaning of jbyteArray, JNIEnv, jobject and jstring.These are required to pass information to and from c program. But I was not able to understand why are JNIEXPORT and JNICALL are used. And what are these termed as in c program(function, Structure, Enum - I regret if this question is very trivial)? Any help is appreciated.

like image 829
hnm Avatar asked Dec 19 '25 13:12

hnm


1 Answers

JNIEXPORT and JNICALL are macros used to specify the calling and linkage convention of both JNI functions and native method implementations.

See here section 12.4

For example, in my jvm (Ubuntu 32bit), the header file jni_md.h contains:

#define JNIEXPORT 
#define JNIIMPORT
#define JNICALL

Which will make your function look like: jbyteArray Java_ReadFile_loadFile (JNIEnv *, jobject, jstring);

While win32 jni_md.h contains:

#define JNIEXPORT __declspec(dllexport)
#define JNICALL __stdcall

Since windows use different calling conventions and your function will look like:

__declspec(dllexport) jbyteArray __stdcall Java_ReadFile_loadFile
(JNIEnv *, jobject, jstring);
like image 177
MByD Avatar answered Dec 21 '25 17:12

MByD