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
Rhino - 09 Feb 2006 14:09 GMT
> VARIANT contains unsigned char*. Pls tell me how to convert it to
> jbyteArray?
[quoted text clipped - 13 lines]
>
> 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?
--
Rhino
Gordon Beaton - 09 Feb 2006 14:50 GMT
> 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

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e