jna.encoding will have no effect if the original string is unicode. You need to use com.sun.jna.WString instead, or see the example W32API mappings for how to automatically map unicode (wchar_t*) strings to String.
Try using a Pointer instead of String and then use the getString(long offset) method of pointer to get the string, it implicitly uses the jna.encoding if set.
发布评论
评论(4)
char* 从 C 方法返回:
char* 传递到 C 方法的参数:
char* Return from C method:
char* Param to pass into C method:
如果原始字符串是 unicode,jna.encoding 将不起作用。 您需要改用 com.sun.jna.WString,或者参阅示例 W32API 映射以了解如何自动将 unicode (wchar_t*) 字符串映射到 String。
jna.encoding will have no effect if the original string is unicode. You need to use com.sun.jna.WString instead, or see the example W32API mappings for how to automatically map unicode (wchar_t*) strings to String.
您是否使用
Native.toString()
将字符串转换回 Java?Did you use
Native.toString()
to convert the string back to Java?尝试使用指针而不是字符串,然后使用指针的 getString(long offset) 方法来获取字符串,它隐式使用 jna.encoding 如果设置了。
Try using a Pointer instead of String and then use the getString(long offset) method of pointer to get the string, it implicitly uses the jna.encoding if set.