简体   繁体   English

如何通过C ++通过JNI传递扩展ASCII字符

[英]how to pass Extended ASCII characters through JNI via C++

I am trying to use JNI via VC++ and pass a custom directory in the classpath as a UTF-8 string -Djava.class.path=c:\\myDir\\my.jar 我正在尝试通过VC ++使用JNI并将类路径中的自定义目录作为UTF-8字符串传递-Djava.class.path = c:\\ myDir \\ my.jar

This works well and I could find the methods in the jar using FindClass 这很好用,我可以使用FindClass在jar中找到方法

But when the directory name contains any extended ASCII characters then FindClass returns NoClassDefFound exception. 但是,如果目录名称包含任何扩展的ASCII字符,则FindClass返回NoClassDefFound异常。 I guess this is becasue the JVM is not able to load the jar file and I am doing something wrong in passing the arguments. 我猜这是因为JVM无法加载jar文件,并且在传递参数时做错了。

Here is what I do 1) Create a std::wstring jarPath(L"-Djava.class.path=C:\\ÆËñœ\\my.jar"); 这是我的工作1)创建一个std :: wstring jarPath(L“ -Djava.class.path = C:\\ÆËñœ\\ my.jar”); 2) Convert the wstring to CP_UTF8 using WideCharToMultiByte 3) copy the utf8String to optionString and call JNI_CreateJavaJVM 2)使用WideCharToMultiByte将wstring转换为CP_UTF8 3)将utf8String复制到optionString并调用JNI_CreateJavaJVM

I have tried printing the convertyed utf8 to a log file just before calling the JNI_CReateJavaJVM and it prints perfectly. 我曾在调用JNI_CReateJavaJVM之前尝试将转换后的utf8打印到日志文件,它可以完美打印。

Could somebody please tell if the CP_UTF8 (defined in windows SDK WinN;sh) is not what the JNI expects? 有人可以告诉我CP_UTF8(在Windows SDK WinN; sh中定义)是否不是JNI期望的? How do I debug this problem, any help is greatly appreciated. 我如何调试此问题,我们将不胜感激。

Thanks in advance Rahul 在此先感谢拉胡尔

The documentation suggests that the option string must be in "the default platform encoding". 文档建议选项字符串必须采用“默认平台编码”。 That probably means you'd need to use CP_ACP. 这可能意味着您需要使用CP_ACP。 If your characters can't be represented in that encoding then I'm not sure there's much you can do. 如果您的字符无法用该编码表示,那么我不确定您可以做很多事情。

(Would the file's short name be usable instead?) (该文件的简称可以使用吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM