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();
}
}