JNative 如何传递复杂参数
有个关于参数传递的问题我该怎么往n = new JNative("rfid.dll","RFID_RetrieveAttachedRadiosList");
的 n中传递对需要的对象??
//***key code:
/** dll 里函数参数类型为
RFID_STATUS RFID_Startup(
RFID_VERSION* pLibraryVersion,
INT32U flags
)
RFID_VERSION 的类型为
typedef struct {
INT32U major;
INT32U minor;
INT32U maintenance;
INT32U release;
} RFID_VERSION;
*/
//关键代码如下
n = new JNative("rfid.dll","RFID_Startup");
//2.设置函数返回值类型
n.setRetVal(Type.INT);
//3.设置参数类型
int i=0;
RFID_VERSION rv = new RFID_VERSION();//参数类 下面已经给出
n.setParameter(0, rv.getPointer());
//执行函数
n.invoke();
//打印参数类的返回值
System.out.println(rv.getValueFromPointer());
//4.执行函数
n.invoke();
//5.获取函数返回值
// System.out.print("正确返回");
System.out.println(R.getValueFromPointer());
/* 打印如下:
RFID_VERSION [major=2, minor=4, maintenance=2, release=240]
*/
return n.getRetVal(); // 返回0:正常。
/*
返回正常结果
*/
//RFID_VERSION 的代码如下
public class RFID_VERSION extends AbstractBasicData<RFID_VERSION> {
public int major;
public int minor;
public int maintenance;
public int release;
public RFID_VERSION() throws NativeException {
super(null);
createPointer();
mValue = this;
}
@Override
public Pointer createPointer() throws NativeException {
pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(getSizeOf()));
return pointer;
}
@Override
public int getSizeOf() {
// TODO 自动生成的方法存根
return 4*8;
}
@Override
public RFID_VERSION getValueFromPointer() throws NativeException {
major = getNextInt();
minor = getNextInt();
maintenance =getNextInt();
release =getNextInt();
return this;
}
@Override
public String toString() {
return "RFID_VERSION [major=" + major + ", minor=" + minor
+ ", maintenance=" + maintenance + ", release=" + release + "]";
}
}
//以上代码正确执行,现dll 有一个方法
RFID_STATUS RFID_RetrieveAttachedRadiosList(
RFID_RADIO_ENUM* pBuffer,
INT32U flags )
/*
参数为
typedef struct {
INT32U length;
INT32U totalLength;
INT32U countRadios;
RFID_RADIO_INFO** ppRadioInfo;
} RFID_RADIO_ENUM;
struct {
INT32U length;
RFID_VERSION driverVersion; //上面已经定义过
INT32U cookie;
INT32U idLength;
INT8U* pUniqueId;
} RFID_RADIO_INFO;
*/
我该怎么往n = new JNative("rfid.dll","RFID_RetrieveAttachedRadiosList");
的 n中传递对需要的对象??
补充:Java , Java相关