定义一个回调函数:
//JNA CALLBACK方法定义,断线回调,如果你是标准的继承StdCallback,否则Callbackpublic interface fDisConnect extends StdCallCallback { public int invoke(NativeLong lLoginID, String pchDVRIP, int nDVRPort, NativeLong dwUser);}
JNA中的回调,采用的匿名内部类:
/** * 断线回调 * * @return */private static dhnetsdklibc.fDisConnect fDisConnect() { return new dhnetsdklibc.fDisConnect() { @Override public int invoke(NativeLong lLoginID, String pchDVRIP, int nDVRPort, NativeLong dwUser) { //注销订阅句柄 if (0 != m_lNativeRealPicHandle.longValue()) { DHUtil.clientStopLoadPic(m_lNativeRealPicHandle); logger.debug("取消订阅图片ok"); m_lNativeRealPicHandle = new NativeLong(0); } return 0; } };}//初始化(项目中只执行一次)DHUtil.initDHSDK(fDisConnect(), null);