开发者

How to pass parameters between JNI and DLL files implemented by C++

the following code is declared in JAVA

private native static Vector< Double > computeSimXML(Vector < String > vDocsPath);

I want to pass the parameter vDocsPath ( defined as Vector < String >) into C++, the code generated by JNI is as follows:(I have implemented some)

/*
 * Class:     SimXMLModule
 * Method:    computeSimXML
 * Signature: (Ljava/util/Vector;)Ljava/util/Vector;
 */
JNIEX开发者_如何学CPORT jobject JNICALL Java_SimXMLModule_computeSimXML
  (JNIEnv *, jclass, jobject)
{
   vector<double>  dist;

   dist.push_back(5.0);
   dist.push_back(6.0);

}

How can I get the value of vDocsPath through jobject, and return dist ( defined as Vector< Double > in JAVA) to JAVA?


This isn't a good function for starting with JNI - implementing it correctly will take some work.

  • The Vector<String> parameter is a plain non-generic Vector runtime.
  • The Vector<Double> return value is a plain non-generic Vector runtime
  • You need to retrieve class and method IDs, and call Vector functions to get data out of the parameter
  • You need to construct a series of Double objects, set the internal double and call Vector methods to setup the return value.

I'd recommend you changed the function signature to:

private native static double[] computeSimXML(String[] vDocsPath);

The JNI interface for working with arrays is a lot simpler than what you're trying to do. You can iterate over parameters with GetArrayLength and GetObjectArrayElement, and you can create and manipulate the return value with NewDoubleArray, GetArrayElements and ReleaseArrayElements

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜