我有以下代码:
public class TTM {
public interface WrapperDLL extends Library {
WrapperDLL INSTANCE = (WrapperDLL) Native.loadLibrary("TransportRE", WrapperDLL.class);
int TRE_send(int channel, Pointer data, int len);
}
public int Send (int channel, String data, int len) {
WrapperDLL wdll = WrapperDLL.INSTANCE;
Memory mem = new Memory(data.length()+1);
mem.setString(0, data);
int byteSent = wdll.TRE_send(channel_id, mem.getPointer(0), len);
// at this (TRE_send) point the VM crashes !!!!
return byteSent;
}
}
看看我试过的 JNA api:
public int Send (int channel, String data, int len) {
WrapperDLL wdll = WrapperDLL.INSTANCE;
Memory mem = new Memory(data.length()+1);
mem.setString(0, data);
int byteSent = wdll.TRE_send(channel_id, mem, len);
return byteSent;
}
这次不会崩溃但不能正常工作(byteSent = 0!)
一些提示?