Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Convert VARIANT to jbyteArray ?

Thread view: 
abhijeet.s - 09 Feb 2006 10:18 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.