I am writing a program in Java and I would like to create a native interface for a library written in C++. But I am confused with how to write a native method declaration for a constructor.
Say I have this C++ class and constructor:
template <class _Tp,class _Val>
class Arbitrator
{
public:
Arbitrator();
}
How would I write a native method declaration?
This is what I'm doing so far: package hbot.proxy.bwsal.arbitrator;
public class Arbitrator<Tp, Val>
{
public native Arbitrator Arbitrator();
}
Is this how I would do this?
Thanks
In order to call a Java class constructor from C++ JNI code, you need to use JNI constructs here. Assuming you have passed a reference to the JVM with JNIEnv in your C++ function like this:
// Function declaration
void
Java_com_hunter_mcmillen_Arbitrator (JNIEnv *env, jobject thiz) {
// Reference to the Java class that has your method
jclass itemClazz = env->FindClass("com/hunter/mcmillen/myjava/myclasses/Arbitrator");
// Reference to the method in your java class
jmethodID constructor = env->GetMethodID(itemClazz, "<init>", "(Ljava/lang/Object;Ljava/lang/Object)V");
}
And now you can actually call the constructor function in your C++ code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With