Symbian
Symbian OS Library

FAQ-0496 How do I export overloaded native functions from a dll?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: JNI
Created: 06/15/2000 Modified: 07/03/2001
Number: FAQ-0496
Platform: Not Applicable

Question:
What do I have to put in the exports.def file if I want to export two native methods with the same name but a different signature in the same class?

Answer:
You need to use the appropriate mangled names or, if you are working with v6 or higher, you can allow an exports.def file to be generated automatically for you by not providing one.
If you look in the header generated by javah you can see what the names get mangled to, e.g., given this class


public class OverloadedJNI
{
public native int foo();

public native int foo(int i);

public native int foo(double d);

public native int foo(Object o);
}


then

javah -jni OverloadedJNI

produces this

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

#ifndef _Included_OverloadedJNI
#define _Included_OverloadedJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: OverloadedJNI
* Method: foo
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_OverloadedJNI_foo__
(JNIEnv *, jobject);

/*
* Class: OverloadedJNI
* Method: foo
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_OverloadedJNI_foo__I
(JNIEnv *, jobject, jint);

/*
* Class: OverloadedJNI
* Method: foo
* Signature: (D)I
*/
JNIEXPORT jint JNICALL Java_OverloadedJNI_foo__D
(JNIEnv *, jobject, jdouble);

/*
* Class: OverloadedJNI
* Method: foo
* Signature: (Ljava/lang/Object;)I
*/
JNIEXPORT jint JNICALL Java_OverloadedJNI_foo__Ljava_lang_Object_2
(JNIEnv *, jobject, jobject);

#ifdef __cplusplus
}
#endif
#endif