2.2 Laden und Linken von native Methoden


NEXT | PREVIOUS | CONTENT

public class NativeHelloWorld {

  public native void   displayHelloworld( );
  public native String inputData( String label );

  static {
    System.loadLibrary( "native" );
  }

  ...

}

Namensauflösung von native Methoden

Durch den Aufruf von: javah -jni NativeHelloWorld entsteht folgende Header-Datei:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class NativeHelloWorld */

#ifndef _Included_NativeHelloWorld
#define _Included_NativeHelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: NativeHelloWorld
* Method: displayHelloworld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_NativeHelloWorld_displayHelloworld
  (JNIEnv *, jobject);

/*
* Class: NativeHelloWorld
* Method: inputData
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_NativeHelloWorld_inputData
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif


JNIEXPORT und JNICALL werden wie folgt in der Datei jni_md.h definiert:
    #define JNIEXPORT __declspec(dllexport)
    #define JNICALL   __stdcall

Escape Sequenz bedeutet
_0XXXX ein Unicode character XXXX.
_1 character "_"
_2 the character ";" in signatures
_3 the character "[" in signatures

Argumente für native Methoden



© 1999 Lars Jordan, Chemnitz Java User Group