You can use JNI (the Java Native Interface) to accomplish this.

a) your C/C++ functions have to be packaged in a shared library (which
you'd already anticipated)

b) the entry point for your C/C++ code has to use a Java
package-and-class-specific "mangled" name -- e.g., if your Java wrapper
class is "Wrapper" and that class is in package "Enclosure", you might have
a Java class such as:

package Enclosure;

public class Wrapper {

        public Wrapper() {
                // ...
        }

        // (only) declare in Java; implement in C/C++ code
        public native String[] getKernelStuff();
}

which would result in a C function name for getKernelStuff() that includes
both the package and class names:

#include <jni.h>

JNIEXPORT jobjectArray JNICALL Java_Enclosure_Wrapper_getKernelStuff
  (JNIEnv *env, jobject theObj) {

        // ...
}


You can pass Java data types to your C code, and xfer/convert Java/C data
types in both directions.

Build your C/C++ code as a shared library, then load that library via Java
using the System.loadLibrary("shortLibName") function, as in:

public class TestTheWrapper {

        public static void main(String[] argv) {
                // this actually loads libWrap.so
                //      (name is platform neutral -- pre/suffixes 
                //              are added implicitly
                System.loadLibrary("Wrap");
                Enclosure.Wrapper w = new Enclosure.Wrapper();
                w.getKernelStuff();
        }
}


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to