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 / January 2006

Tip: Looking for answers? Try searching our database.

Java String to LPCWSTR Question

Thread view: 
res7cxbi@verizon.net - 15 Jan 2006 03:55 GMT
How do you convert a jbyte* that i get from GetStringUTFChars in JNI to
an LPCWSTR?
Roedy Green - 15 Jan 2006 09:19 GMT
>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.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Chris Uppal - 15 Jan 2006 10:06 GMT
> > 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.

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

   -- chris
Roedy Green - 15 Jan 2006 12:42 GMT
On 15 Jan 2006 10:06:51 GMT, "Chris Uppal"
<chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly
quoted someone who said :

>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

res7cxbi@verizon.net - 15 Jan 2006 18:06 GMT
What about TCHAR? Can i use that?
Chris Uppal - 16 Jan 2006 12:22 GMT
> 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
Chris Uppal - 15 Jan 2006 10:33 GMT
> 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


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.