Java JNA回调实现方式

//接口
public interface HvCallback {
public static interface PLATE_NO_CALLBACK extends Callback {
int invoke(HvResult lpParam, String pString, int dwStrLen, int dwType);
}
}
//接口实现,invoke中的参数与c++中的参数相对于
public static class PlateNoCallBack implements PLATE_NO_CALLBACK {
@Override
public int invoke(HvResult lpParam, String pString, int dwStrLen, int dwType) {
System.out.println(“回调会的数据:”);
return 1;
}
}
//c++中的参数要求
typedef INT (CDECL* HVAPI_CALLBACK_TFD_STRING)(
PVOID pUserData,
LPCSTR pString,
DWORD dwStrLen,
DWORD dwType
)
//执行的回调步骤
static public PlateNoCallBack plateNoFunction = new PlateNoCallBack();
public boolean receiveInfo(){
int resultReceive2 = HVInterface.INSTANCE.HVAPI_SetCallBackEx(DevResult.hv_devHandle, plateNoFunction, DevResult, 0, CALLBACK_TYPE_TFD_STRING,null);
System.out.println(“receive:”+resultReceive2);
if(resultReceive2 == 0 ){
return true;
}
return false;
}