JNA调用C的DLL,如何取回当初传入的字符指针的修改值
1个回答
展开全部
C代码extern "C" int _declspec(dllexport) getXMLResult(char *result){result = "abcd";return 20;}这个函数的目的是传入字符指针,在函数内容修改指针指向的字符串内容java代码public class JNATest {
// This is the standard, stable way of mapping, which supports extensive
// customization and mapping of Java to native types.
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary("TestDLL.dll", CLibrary.class);
//函数声明byte[]和String都试过,都不行,改变不了传递进去的字符串
int getXMLResult(byte[] result);}/*** @param args*/public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("begin");
//WString s = new WString("Hello, World");
//System.out.println("s="+s.toString());
byte[] c = {'a','a','a','a'};
System.out.println("c="+Native.toString(c));
//ByteByReference[] iref = new ByteByReference[4];
int i = CLibrary.INSTANCE.getXMLResult(c);
System.out.println("i="+i);
System.out.println("c="+Native.toString(c));
//System.out.println("s="+s.toString());
System.out.println("end");}}Java中byte[] c初始化,调用DLL中函数,但byte[] c的值没有被修改。
===============================================================
// This is the standard, stable way of mapping, which supports extensive
// customization and mapping of Java to native types.
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary("TestDLL.dll", CLibrary.class);
//函数声明byte[]和String都试过,都不行,改变不了传递进去的字符串
int getXMLResult(byte[] result);}/*** @param args*/public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("begin");
//WString s = new WString("Hello, World");
//System.out.println("s="+s.toString());
byte[] c = {'a','a','a','a'};
System.out.println("c="+Native.toString(c));
//ByteByReference[] iref = new ByteByReference[4];
int i = CLibrary.INSTANCE.getXMLResult(c);
System.out.println("i="+i);
System.out.println("c="+Native.toString(c));
//System.out.println("s="+s.toString());
System.out.println("end");}}Java中byte[] c初始化,调用DLL中函数,但byte[] c的值没有被修改。
===============================================================
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询