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的值没有被修改。
===============================================================