如何在JNI中创建给定地址和类的指针

时间:2016-08-03 02:43:54

标签: java c++ c java-native-interface

如果我使用内存地址和存储在该地址的数据类型调用本机方法,如何在JNI中创建指向该地址的指针?

在Java中:

pointers(long.class, 810234092817);

在JNI:

JNIEXPORT jlong JNICALL Java_JNIFoo_pointers
    (JNIEnv *env, jobject obj, jclass cls, jlong addr) {

   // if cls is long, then i want to dynamically create the following 
   // b/c i know the data at *addr* is of type *cls*.
   // This works. 
   jlong* p = (jlong *) addr;

   // jclass has the class type and addr has the actual address. But I can't do this
   (cls*) p = (cls *) addr;
}

如何创建指向jlong类型jclass地址的指针?

0 个答案:

没有答案