使用JNative调用dll,传入参数错误。
itkai 2014-02-10 11:55:42 使用JNative调用dll,传入参数错误,请大家帮忙看下,怎么才能正确传入。谢谢。
dll函数:
DPSDK_DLL_API int32_t DPSDK_CALL_METHOD DPSDK_Login (IN int32_t nPDLLHandle, IN Login_Info_t* pLoginInfo, IN int32_t nTimeout);
typedef struct tagLoginInfo {
char szIp; // 服务IP
char szUsername; // 用户名
char szPassword; // 密码
dpsdk_protocol_version_e nProtocol; // 协议库类型,000、001、002
}Login_Info_t;
typedef enum {
DPSDK_PROTOCOL_VERSION_I = 1,
DPSDK_PROTOCOL_VERSION_II = 2,
}dpsdk_protocol_version_e;
现JNative调用:
public class DssLogin extends AbstractBasicData<DssLogin> {
public static void main(String[] args) throws NativeException,
IllegalAccessException {
System.out.println(getDssLogin());
}
public static int getDssLogin() throws NativeException,
IllegalAccessException {
JNative jnative = new JNative("DPSDK_Core", "DPSDK_Login");
jnative.setRetVal(Type.INT);
jnative.setParameter(0, 1);
DssLogin dssLogin = new DssLogin();
jnative.setParameter(1, dssLogin.getPointer());
jnative.setParameter(2, 10000);
jnative.invoke();
return Integer.parseInt(jnative.getRetVal());
}
public DssLogin() throws NativeException {
super(null);
createPointer();
}
@Override
public Pointer createPointer() throws NativeException {
pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(getSizeOf()));
pointer.setStringAt(0, "192.168.1.108");
pointer.setIntAt(1, 9000);
pointer.setStringAt(2, "system");
pointer.setStringAt(3, "123456");
pointer.setStringAt(4, "001");
return pointer;
}
@Override
public int getSizeOf() {
return 64;
}
@Override
public DssLogin getValueFromPointer() throws NativeException {
return null;
}
}