I could not come up with better title so here it is. I am trying to figure out what would be the best way (in case of efficiency and clean code wise) of accessing methods from stdlib of C. Background for that is that I am trying to get a functionality of mbstowcs in Java program. Right now in my C code I have got this:
const char* source = "D:\\test3\\source\\test.txt";
SName tmp1;
mbstowcs((wchar_t*)tmp1, source, 32 - 1);
Where SName
is typedef unsigned short SName[32]
. Later in code tmp1
is being used as an input argument:
status = copyFilePath(tmp1, tmp2, info, &context);
What I am essentially trying to do is to call this copyFilePath
from Java side using JNA. The trick is that I would need to get similar conversion to C's mbstowcs in Java program so later I could directly call this function without any additional processing. For now it seems to me that I would be needing additional C code with in use of JNI so I could get a wrapper for mbstowcs from stdlib.
Question also is, are there any similiar ways for Java to convert multibyte string to wide-character string just like in C/C++ to get it all working out?
Not answering the question but trying to help with the problem. JNA has com.sun.jna.WString
. If you invoke a Function with a WString parameter, it will turn up as a wide string in the native code. You will only have to make sure that you've got the correct encoding.
Instead of function.invoke(myString);
which gives you a multibyte string on the native side, just use function.invoke(new WString(myString));