Java String to LPCWSTR Question

R

res7cxbi

How do you convert a jbyte* that i get from GetStringUTFChars in JNI to
an LPCWSTR?
 
R

Roedy Green

How do you convert a jbyte* that i get from GetStringUTFChars in JNI to
an LPCWSTR?

look in the headers to find out what a jbyte* really is. Then it
becomes a C problem.
 
C

Chris Uppal

Roedy said:
look in the headers to find out what a jbyte* really is. Then it
becomes a C problem.

Roedy, if you don't know the answer then don't just /guess/., The
above is bad advice in several different ways.

-- chris
 
C

Chris Uppal

How do you convert a jbyte* that i get from GetStringUTFChars in JNI to
an LPCWSTR?

Two ways.

One is to use the data from GetStringUTFChars(), which -- despite the name --
is /NOT/ in UTF-8 format, to build a new wide-string. To do that you'll have
to look at the definition of the non-UTF-8 format in the JNI documentation.
Tedious and easy to make mistakes, but not actually difficult.

The other is to use the other API, GetStringChars() (if I remember the name
correctly), instead. That will give you a sequence of 16-bit values in UTF-16
format, which is the same as that used by Windows, and (presumably) what you
want your LPCWSTR to contain. Note that GetStringChars() does /not/ return
null-terminated data. I /think/ that most uses of LPCWSTR expect the data to
be null-terminated, but I'm not sure.

-- chris
 
R

Roedy Green

Roedy, if you don't know the answer then don't just /guess/., The
above is bad advice in several different ways.

If you think my answer is wrong. please give the right one, or at
least explain how it was wrong.
 
C

Chris Uppal

What about TCHAR? Can i use that?

Please quote appropriately from the message to which you are replying. If your
newsreader is so broken that it is difficult to do that (e.g. if you have been
so mislead by Google as to suppose that Usenet is part of Google) then do it by
hand or -- a far better idea -- get a proper newsreader.

I do not normally reply to authors who cannot be bothered to learn, or are so
clueless not to have noticed the existence of, basic Usenet etiquette. On this
occasion, however, having got that off my chest, I may as well carry on and try
to answer what I guess is your question.

TCHAR is part of the MS infrastructure for hiding the difference between 8-bit
characters and 16-bit characters. It's a bit of a hack (actually, it's a hack
from bottom to top), but it does work moderately well. In this case you don't
/want/ to hide the difference, since you are definitely working with 16-bit
unsigned quantities so I suggest that using TCHAR is actively wrong since TCHAR
can expand to char or wchar_t depending on the compilation environment.

-- chris
 

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

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top