Re: how to communicate unsigned char* to Java

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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!



.



Relevant Pages

  • Re: how to wait for socket communications
    ... how to communicate the chars to Java. ... The picture information is an unsigned char*, with first all the red values ...
    (microsoft.public.win32.programmer.networks)
  • Re: Is VB.NET dead?
    ... important in communication, it is understanding that writes good software. ... Of course, in the case of programming languages, the ... the similarity between the syntax of C# and Java ... is not one of "mere" punctuation. ...
    (microsoft.public.dotnet.general)
  • Re: find certain strings in java files not inside comments
    ... > I want to determine if there any of the following strings in a java ... > with a list of java files starting at $ARGV. ... > /* blah blah blah ... > foreach(@ARGV) ...
    (comp.lang.perl.misc)
  • Re: Java compatibility issues (WAS: MF having issues?)
    ... I believe, that the JLS (Java Language Specification) REQUIRES that this optimization be done. ... package testPackage; ... true true true true false true ... * Literal strings within different classes in the same package represent references to the same String object. ...
    (comp.lang.cobol)
  • Re: afraid of .NET
    ... People will start on Messenger but that doesn't mean IRC is at an end. ... MSN, to me, is more for "one on one" communication, and IRC is more of a round-table, everyone at the same time, communication. ... I having taken a close look at the licenses in question, so I don't really know how much merit this argument has, but I know some of my hardcore GNU/GPL friends refuse to use Java because of its license. ...
    (comp.lang.java.advocacy)