Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass a LPWSTR to java via JNI. But, it only passes the first character of the string. Can someone suggest what to do? I'm passing the string like the following:

jstring k = (*env)->NewStringUTF(env, lpstr);               
    jstring v = (*env)->NewStringUTF(env, lpstr);                   
    (*env)->CallObjectMethod(env, hashMap, putMethodID, k, v);


What I have tried:

I have tried using _tcscpy(). But it shows error.
Posted
Updated 16-May-21 7:24am

It's acting like the JNI is expecting single-wide characters for that function because in a wide string the second byte of the pair will be zero for characters less than 256 so the function is seeing a string of a single character.

Your options are to call a function that will accept a wide string or convert your wide string to a "narrow" string first and then pass that to the function.
 
Share this answer
 
Working with strings isnt so easy at all because every string has "under the hood" some encoding logic. This mean HOW the buffer of bytes is interpreted to the human readable string. Try also Memory view to see the details byte by byte.

For this complex topic I suggest you to read this string article. Take the time to understand the nuts and bolts of strings.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900