zoukankan      html  css  js  c++  java
  • C# 结构体数组 C++ DLL

     大华人脸识别 C++文档

    方法:当 _iCmdId =  6,_lpIn 为输入的结构体参数 FaceLibQuery ,_lpOut 为输出的结构体数组 FaceLibQueryResult

      _lpOut为FaceLibQueryResult数组,数组大小为每页个数,_iOutLen值为sizeof(FaceLibQueryResult),非数组大小。

    结构体:

     

     C#调用

     [DllImport("NVSSDK.dll", SetLastError = true)]
    public static extern Int32 NetClient_FaceConfig(Int32 _iLogonId, Int32 _iCmdId, Int32 _iChanNo, IntPtr _lpIn, Int32 _iInLen, IntPtr _lpOut, Int32 _iOutLen);
        [StructLayout(LayoutKind.Sequential)]
        struct FaceLibQuery
        {
            public int iSize;
            public int iChanNo;
            public int iPageNo;
            public int iPageCount;
        };
        [StructLayout(LayoutKind.Sequential)]
        struct FaceLibQueryResult
        {
            public int iSize;
            public int iChanNo;
            public int iTotal;
            public int iPageNo;
            public int iIndex;
            public int iPageCount;
            public FaceLibInfo tFaceLib;
        };
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
        struct FaceLibInfo
        {
            public int iSize;
            public int iLibKey;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = CommonLen.LEN_64)]
            public byte[] cName;
            public int iThreshold;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = CommonLen.LEN_64)]
            public byte[] cExtrInfo;
            public int iAlarmType;
            public int iOptType;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = CommonLen.LEN_UUID)]
            public byte[] cLibUUID;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = CommonLen.LEN_64)]
            public byte[] cLibVersion;
        };
       FaceLibQuery tQuery = new FaceLibQuery(); 
       tQuery.iSize = Marshal.SizeOf(tQuery);
       tQuery.iChanNo = m_iChannelNo;
       tQuery.iPageNo = 0;     //要查询的页码,iPageNo >= 0。
       tQuery.iPageCount = 20;   //查询的每页个数,取值范围[1,20]。
    
       IntPtr ipQueryInfo = Marshal.AllocHGlobal(Marshal.SizeOf(tQuery));
       Marshal.StructureToPtr(tQuery, ipQueryInfo, true);//false容易造成内存泄漏
    
       //封送结构体数组,搭建输出的结构体数组
       FaceLibQueryResult[] tResult = new FaceLibQueryResult[20];
       for (int i = 0; i < tResult.Length; i++)
       {
           tResult[i] = new FaceLibQueryResult();
       }
       IntPtr ipResult = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FaceLibQueryResult)) * 20);
    
       int iRet = -1;
       iRet = NVSSDK.NetClient_FaceConfig(m_iLogonId, NVSSDK.FACE_CMD_LIB_QUERY, m_iChannelNo, ipQueryInfo, Marshal.SizeOf(tQuery),
               ipResult, Marshal.SizeOf(typeof(FaceLibQueryResult))); //还原搭建的输出的结构体数组 for (int i = 0; i < 20; i++) { IntPtr ptr = (IntPtr)((UInt32)ipResult +
                  i * Marshal.SizeOf(typeof(FaceLibQueryResult))); tResult[i] = (FaceLibQueryResult)Marshal.PtrToStructure(ptr, typeof(FaceLibQueryResult)); Console.WriteLine("人脸库:" + Encoding.Default.GetString(tResult[i].tFaceLib.cName)); } Marshal.FreeHGlobal(ipQueryInfo); Marshal.FreeHGlobal(ipResult);
  • 相关阅读:
    2016(4)数据库系统,ER模型,规范化理论,并发控制
    2016(3)系统设计,嵌入式系统
    2016(2)系统设计,面向对象设计方法,需求工程,面向对象需求分析
    2016(1)系统规划,可行性分析,成本效益分析
    2017(5)软件架构设计,web系统的架构设计,数据库系统,分布式数据库
    2017(4)数据库系统,分布式数据库,NoSQL,反规范化
    2017(3)系统设计,嵌入式多核程序设计
    2017(2)数据库设计,数据库设计过程,ER模型,规范化理论
    2017(1)软件架构,架构风格,微服务
    2018(5)软件架构设计,架构风格,REST
  • 原文地址:https://www.cnblogs.com/HansZimmer/p/12485234.html
Copyright © 2011-2022 走看看