java jna调用C++外部函数指针缓冲区参数如何定义和传递

u013100836 2020-06-12 09:50:48
动态库提供一个外部函数 IVS_SDK_GetDeviceList, pCameraInfoList用于获取信息指针
//cpp code,定义100个IVS_CAMERA_BRIEF_INFO_LIST数据结构缓存,通过IVS_SDK_GetDeviceList方法指针参数返回缓冲区
int uiReqNum = 100;
int uiRsqBufSize = sizeof(IVS_CAMERA_BRIEF_INFO_LIST) + (uiReqNum-1) * sizeof(IVS_CAMERA_BRIEF_INFO);// 计算缓存大小
IVS_CAMERA_BRIEF_INFO_LIST* pCameraInfoList = (IVS_CAMERA_BRIEF_INFO_LIST*)(new IVS_CHAR[uiRsqBufSize]);//分配内存
int iRet = IVS_SDK_GetDeviceList(null, 0, &IndexRange, pCameraInfoList, uiRsqBufSize);

我的问题是,使用java jna使用该外部函数时,pCameraInfoList这一块缓冲区参数如何定义和传递?返回后如何从缓冲区100个数据集,逐条取得信息?
...全文
318 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
十八道胡同 2020-06-12
  • 打赏
  • 举报
回复
import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
//import java.util.concurrent;

public class CoreSoTest {
    public static void main(String[] args) {
        System.out.println("参数初始化开始--1");
        DllService dllService = DllService.INSTANCE;
        System.out.println("参数初始化开始--2");
        Pointer pointer = new Memory(10240);
        dllService.Init("/home/lich/TestJava/PriceTxt",
                "/home/lich/TestJava");
        System.out.println("参数初始化开始--3");
        int count = 10000;
        //while (count > 0) 
        {
            int ret = dllService.GetXX(
                    "870501246F6CA27320191224182541,3513,2019-12-21T18:22:40,1904,2029-12-24T18:39:51,591F06,",
                    pointer);
            System.out.println(count + "->" + ret + "->" + pointer.getString(0));
            count--;
        }
      
        try {
            dllService.DeInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    interface DllService extends Library {
        DllService INSTANCE = (DllService) Native.loadLibrary("CSLinux", DllService.class);
        DllService INSTANCE2 = (DllService) Native.synchronizedLibrary(INSTANCE);

        boolean Init(String feedir, String logdir);

        int GetXX(String paramString, Pointer resultString);

        int DeInit();
    }
}
我的例子,给你参考

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧