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);
  • 相关阅读:
    上涨、下跌、震荡,我只做下跌 (有钱人赚钱太有心机!
    股票操作指南
    股票要素与心理学研究
    时序图组成
    软件描述的静态与动态
    用dedecms做网站时,空间服务器选择IIS还是apache???
    dedecms 图集标签{dede:productimagelist} {dede:field name='imgurls'}&nbs
    dede内容页调用图片集下所有图片方法!
    dede文章插入分页符不起作用,编辑器中出现分页符,导致文章显示不全
    dede织梦怎么修改description的字数
  • 原文地址:https://www.cnblogs.com/HansZimmer/p/12485234.html
Copyright © 2011-2022 走看看