Is this a valid .h C header file that can be used for Java Native Interface JNI?

101 views Asked by At

I'm trying to understand if the file that was provided to me is something I can use Jave Native Interface with, where I can write a Java class and create native abstract methods corresponding to C functions in the .h header file.

So, what I have now is a .ec file and .h file. Both were provided to me. I was asked to try to use JNI to invoke functions from .ec file.

However, I noticed that some common JNI keywords like JNIEXPORT, JNICALL, JNIEnv*, jobject are NOT present in either .ec or .h files that was given to me.

The .h file looks like this :

#ifndef _BITMAP_H
#define _BITMAP_H 1

struct BITMAP
{
    char *buffer;   // buffer 
    int   ax;       // width
    int   ay;       // height
    int   size;     // buffer size
};
struct BITMAP *create(int ax, int ay);
void close( struct BITMAP *pbmp );
void drawLn( struct BITMAP *pbmp, int x1, int y1, int x2, int y2 );
void drawTxt(struct BITMAP *pbmp, char *szText, int x, int y );
void setPxl( struct BITMAP *pbmp, int x, int y );
#endif

Is this a valid file to use JNI with? I'm a total beginner with JNI but I suspect, and it looks like JNI is not applicable to this kind of file definition.

Are there other Java technology or library to invoke these methods from .ec file?

I'd appreciate any comment or explanation.

Thank you.

1

There are 1 answers

1
Sync it On

Answer is NO its not a valid header file. You don't look at java native code and try to create a header file by hand instead you let javac generate the header file for you using the -h option

-h directory Specifies where to place generated native header files.

When you specify this option, a native header file is generated for each class that contains native methods or that has one or more constants annotated with the java.lang.annotation.Native annotation. If the class is part of a package, then the compiler puts the native header file in a subdirectory that reflects the module name (if appropriate) and package name. The directory, and any necessary subdirectories, will be created if they do not already exist.

Javac will compile class files containing native methods and will output the header files for you. Documentation here