recipe № 004

passing long value from Java to C

In this sample we will pass long into C code from Java. After you finish this tutorial, you should end up with the directory structure similar to this one

First of all, we need a Java class that will call native code. That’s fairly simple

Notice the difference comparing to HelloWorld sample. Above, in native method we declare that we will pass long value. You can also tell the difference in static block. This time, we load PassLong library. In real world applications, most of the native code will be stored in the same library. Here, I will put each function into separate file.

Again, we have to compile the class and create native’s code header

After header is created

we can create implementation of the function and compile the code

Compilation is plain and simple

After all elements are in place, all we have to do is to run the sample

As you can see, we can read what was passed to native code as it was written to stdout. And that’s what we wanted to get.