I have been trying to call a C function that has the following signature
int changeFoo(L_TCHAR* pszFileSrc){....}
in my JNI call my method looks like this:
JNIEXPORT jint JNICALL Java_com_me_L_AFoo(JNIEnv * env, jclass jclass, jstring pSrc)
{
jint retValue = -100;
retValue = changeFoo(pSrc);
return retValue;
}
I get the following error in visual studio.
Error 1 error C2664: ‘L_FileConvert’ : cannot convert parameter 1 from ‘jstring’ to ‘L_TCHAR *’ c:\Ayusman\Work\MyVCpp\LTExampleDll\LTExampleDll\LTExampleMain.cpp 46 LTExampleDll
When I looked at the definition of L_TCHAR *
here is what I got in the header files (in that sequence):
typedef TCHAR L_TCHAR;
typedef WCHAR TCHAR,*PTCHAR;
typedef wchar_t WCHAR; //wc, 16 bit UNICODE char
I work on java, this is a JNI application that I am trying to build.
Can any body help as to how can I convert this properly?
You’ll have to manually convert the string. Here’s some (corrected) example code:
Note that this code only applies if you’re using Java 5 or above and your wchar_t data type is four bytes long. If you’re using Java 1.4 or below or your wchar_t data type is two bytes long then you don’t have to worry about surrogates.
This code also leaves out some basic error checking and assumes that the first surrogate in the pair is the high-order surrogate (which is the case on my machine). You can definitively tell which surrogate is the high-order surrogate and which is the low-order surrogate by their respective values. The high-order surrogate is between 0xD800 and 0xDBFF, inclusive. The low-order surrogate is between 0xDC00 and 0xDFFF, inclusive. If you find a high-order surrogate that isn’t paired with a low-order surrogate or a low-order surrogate that isn’t paired with a high-order surrogate then the string is coded incorrectly.