How to put a C char[] result into a jave BufferType variable ?

I have a serious problem; in fact i am interested in retrieving some data with JNI , my V function return a char [] and i want to store it in a ByteBuffer variable in the java code that invoke my C function :

unsigned char video[MAX_NB_CELL]; // variable declared and returned by the C function

ByteBufer MyVideo; // the java variable that is used to store the C Variable

in other words i am trying to have something like the following ; MyVideo = video

so how can i do it given that the 2 variables are not in the same type!!

thanks

[572 byte] By [Ramazottia] at [2007-10-3 1:14:41]
# 1

This is a simple example on how to use [url http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/functions.html#new_direct_byte_buffer]NewDirectByteBuffer[/url]:// C:

char[] your_c_func(int * c_array_length) {

...

}

// JNI:

JNIEXPORT jobject JNICALL Java_YourClass_yourNativeMeth(JNIEnv * env, jobject obj) {

int c_array_length;

char[] c_array = your_c_func(&c_array_length);

jobject j_byte_buffer = (*env)->NewDirectByteBuffer(env, c_array, c_array_length);

return j_byte_buffer;

}

// Java:

class YourClass {

native ByteBuffer yourNativeMeth();

}

Regards

jfbrierea at 2007-7-14 18:11:46 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

HI ,

I tried to retrieve the byte buffer as suggested but here is the error that i got !! can someone help me please!!

#

# An unexpected error has been detected by HotSpot Virtual Machine:

#

# SIGSEGV (0xb) at pc=0xb29c45fe, pid=3773, tid=2982861744

#

# Java VM: Java HotSpot(TM) Client VM (1.5.0_05-b05 mixed mode, sharing)

# Problematic frame:

# J java.nio.DirectByteBuffer.get(I)B

#

# An error report file with more information is saved as hs_err_pid3773.log

#

# If you would like to submit a bug report, please visit:

#http://java.sun.com/webapps/bugreport/crash.jsp

#

Ramazottia at 2007-7-14 18:11:46 > top of Java-index,Java HotSpot Virtual Machine,Specifications...