Re: how to communicate unsigned char* to Java
- From: Ananya <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 22 May 2007 02:43:02 -0700
Actually, I did find out that getBytes does not get the lower byte, and even
worse, the Java characters don't seem to allow arbitrary values. So it looks
like I have to figure out how to read my file in Java as bytes.
"Ananya" wrote:
Cant't I just use char* in C++ and String[] string in Java and.
byte[] bytes = string.getBytes()
which gets the lower bytes of the two bytes?
"Alexander Nickolov" wrote:
I'm pretty certain you must _not_ use a string on the Java side.
Java strings are UTF16 encoded, whereas you have binary
data not suitable for a string. On the C++ side don't use any
string functions either - char* is not reserved for strings only -
it's used for binary data as well.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Ananya" <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C056C161-C1A3-4082-8807-E32B9BD4E607@xxxxxxxxxxxxxxxx
I convert the unsigned char* to char* in C++ using reinterpret_cast<char*>.
But when I recieve the char ch in Java, neither
int i = ((int)(ch)>>8) & 255 (reversing the order of bytes)
nor
int i = (int)(ch) & 255
seems to give the same value as the value of the unsigned char in C++.
What's a correct and fast way to make this communication?
Thanks for your time!
"Ananya" wrote:
I am calling a Java native executable from a C++ program.
I would like to communicate the red, green, and blue values of an image,
which are unsigned chars in my C++ program (varying between 0 and 255) to
my
Java program.
Well I first convert my unsigned char* to char*, but chars in C++ are 1
byte
and chars in Java are 2 bytes.
What's a fast and correct way to make this communication?
Thanks for looking at this!
- Follow-Ups:
- References:
- Re: how to communicate unsigned char* to Java
- From: Alexander Nickolov
- Re: how to communicate unsigned char* to Java
- Prev by Date: Re: receiving binary data over socket
- Next by Date: RE: Windows Vista and NetSharingManager.EnumEveryConnection
- Previous by thread: Re: how to communicate unsigned char* to Java
- Next by thread: Re: how to communicate unsigned char* to Java
- Index(es):
Relevant Pages
|