定義一個回調函數:java
//JNA CALLBACK方法定義,斷線回調,若是你是標準的繼承StdCallback,不然Callback public interface fDisConnect extends StdCallCallback { public int invoke(NativeLong lLoginID, String pchDVRIP, int nDVRPort, NativeLong dwUser); }
JNA中的回調,採用的匿名內部類:ide
/** * 斷線回調 * * @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);