原文:https://www.cnblogs.com/wyongbo/p/jnaTest.html

原文链接:https://blog.csdn.net/qq_18219457/java/article/details/93905147

这两篇文章已经讲得非常清楚了。

但在实际操作的时候,由于C#使用了SQLite,而SQLite的相关库是x86的,因此,java的jdk和c++以及C#环境都需要设置为x86运行环境。

x86  jdk下载地址:

https://www.cr173.com/soft/79926.html

Java使用JNA调用C# dll方法

补充:调用过程中,当存在中文输入/输出时,出现乱码。

解决方案:两边的输入输出通过base64的方式进行交互

Java端:

     // 将 s 进行 BASE64 编码 
     public static String getBASE64(String s) { if (s == null) return null; return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); } 
     // 将 BASE64 编码的字符串 s 进行解码 
     public static String getFromBASE64(String s) { if (s == null) return null; sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b); } catch (Exception e) { return null; } }
View Code

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2021-09-17
  • 2019-01-09
  • 2021-09-10
  • 2022-12-23
  • 2021-08-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案