X hits on this document

314 views

0 shares

0 downloads

0 comments

100 / 120

generated header file will contain a function prototype that reflects the fully qualified

name and signature of the method. Using the function prototype, it is the responsibility

of the programmer to write a C/C++ method that conforms to it and interacts properly

with the JVM. Please note that garbage collection does not apply to any memory

allocated by the native code, so be sure to free it.

To generate the JNI header file, we must first declare a native method in

JsimpleCalculator.java that we wish to implement in C/C++. In addition, we must also

indicate the name of the DLL Java will need to load in order to call it. Table 9.6 contains

the needed additions to JsimpleCalculator.java to declare the native method. Note that

on the System.loadLibrary call, the file extension of the DLL file is not specified.

Table 9.6. Example native method declaration for the JNI XML bridge.

01: public class JSimpleCalculator implements ISimpleCalculator 02: {

03: 04: 05: 06: 07: 08:

native String smplCalcXmlInterface(String xmldoc); static { System.loadLibrary("Java2CblXmlBridge"); } ...

09:

}

When using the javah command-line utility, keep in mind that it operates on

*.class files instead of *.java files; this is because the Java reflection APIs are used to get

the qualified name and signature of the native method declaration instead of having to

parse the source file. To generate a C/C++ header file from the JSimpleCalculator.class

file, issue the command “javah -jni

info.reversingproject.jsimplecalculator.JSimpleCalculator.

Table 9.7 gives the source

92

Document info
Document views314
Page views315
Page last viewedSun Dec 04 08:56:17 UTC 2016
Pages120
Paragraphs2913
Words25794

Comments