java jna 回调函数_jna设置回调函数接收c++数组

本文介绍如何在Java中使用JNA库来调用C++的回调函数,特别是涉及到设置回调函数接收C++数组的方法。通过示例代码展示了如何加载动态链接库,初始化、启动和停止SDK,并实现回调接口,以及在回调中处理阻塞等待数据的场景。
摘要由CSDN通过智能技术生成

import com.sun.jna.Callback;

import com.sun.jna.Library;

import com.sun.jna.Native;

import com.sun.jna.win32.StdCall;

import lombok.extern.log4j.Log4j2;

@Log4j2public classTest {

CLibrary cLibrary;public interfaceCLibrary extends Library, StdCall {

CLibrary INSTANCE=(CLibrary)

Native.loadLibrary("D:\\subway\\MicsDataSdk\\MicsDataSdk.dll", CLibrary.class);voidCMicsDataSDK();//获取版本号

String Common_GetVersion();//初始化

intCommon_Init(String configPath, String logPath);intCommon_Start();intCommon_Stop();intCommon_SetCallback(CLibrary xx, Callback back);

}public static voidmain(String[] args) throws InterruptedException {

Thread thread= new Thread(()->{

String configPath="D:\\project\\MicsDataSdk\\config.ini";

String logPath="";

CLibrary.INSTANCE.CMicsDataSDK();

CLibrary.INSTANCE.Common_Init(configPath,logPath);

IMyDllCallback callback= newMyDllCallbackImpl();

String s=CLibrary.INSTANCE.Common_GetVersion();

System.out.println(s);

CLibrary.INSTANCE.Common_SetCallback(null,callback);

CLibrary.INSTANCE.Common_Start();

log.info("sdk启动");

synchronized (callback) {try{

System.out.println("进入阻塞,等待数据中...");

callback.wait();

System.out.println("阻塞完成");

}catch(InterruptedException e) {

e.printStackTrace();

}

}

});

thread.run();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值