Convert VARIANT to jbyteArray ?

A

abhijeet.s

VARIANT contains unsigned char*. Pls tell me how to convert it to
jbyteArray?

jbyteArray _byte_array;
VARIANT _tmpval;
long _lBound = 0;
long _uBound = 0;
SafeArrayGetLBound(_tmpval.parray,1,&_lBound);
SafeArrayGetUBound(_tmpval.parray,1,&_uBound);
const int _size = _uBound - _lBound + 1;
unsigned char _buf[500];
SafeArrayAccessData(_tmpval.parray,(void**)&_buf);
_byte_array = _jnienv->NewByteArray(_size);
_jnienv->SetByteArrayRegion(_byte_array, 0, _size, (jbyte *)_buf);
SafeArrayUnaccessData(_tmpval.parray);

Is it correct?

Regards
Abhijeet
 
R

Rhino

abhijeet.s said:
VARIANT contains unsigned char*. Pls tell me how to convert it to
jbyteArray?

jbyteArray _byte_array;
VARIANT _tmpval;
long _lBound = 0;
long _uBound = 0;
SafeArrayGetLBound(_tmpval.parray,1,&_lBound);
SafeArrayGetUBound(_tmpval.parray,1,&_uBound);
const int _size = _uBound - _lBound + 1;
unsigned char _buf[500];
SafeArrayAccessData(_tmpval.parray,(void**)&_buf);
_byte_array = _jnienv->NewByteArray(_size);
_jnienv->SetByteArrayRegion(_byte_array, 0, _size, (jbyte *)_buf);
SafeArrayUnaccessData(_tmpval.parray);

Is it correct?
I don't understand your question. I'm not familiar with VARIANT or
jbyteArray and I've been writing Java since 1997. I had a little bit of C
language many years ago and the code you've posted looks a lot more like C
language than Java. Are you sure you don't want a C programming newsgroup?

Or are you trying to cnvert this code to Java?
 
G

Gordon Beaton

VARIANT contains unsigned char*. Pls tell me how to convert it to
jbyteArray?
[...]

Is it correct?

What happened when you tried?

Most of the code you've shown is uninteresting for the question, since
it involves methods specific to VARIANT, whatever that is, which has
nothing to do with Java or JNI.

However if you have a buffer of char and a jbyteArray, you can do this
(taken more or less directly from the JNI docs):

jbyteArray ba = env->NewByteArray(size);
env->SetByteArrayRegion(ba, 0, size, buf);

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top