hnm
hnm

Reputation: 829

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.

Upvotes: 3

Views: 994

Answers (1)

MByD
MByD

Reputation: 137382

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);

Upvotes: 4

Related Questions