none
求助?这个结构如何转换到C# RRS feed

  • 问题

  •  typedef struct THID_ATM2G3_Result
     {
      CRITICAL_SECTION cs;
      THID_ATM2G3_WarningType nEvtType; // 0:心跳
      int      time;  // 心跳、报警时间(__time32_t)

      //int  nLinkageExt; // 扩展报警类型, when (nEvtType==THID_ATM2G3_LINKAGE_Ext)
      int  nLogicChannel; // 报警的逻辑通道,-1表示未指定,0表示面板通道,1表示人脸通道,2表示SSB,3表示加钞间

      // ATM 面板、异常人脸  // IPNA_WARNING_ATMG3_ATM_PASTE
      int      nNumWarn;    // 报警区域数目
      int      nNumWarnMax;
      THID_ATM2G3_RegionInfo *region;

      // 保存人脸抓拍结果:THID_ATM2G3_FACE_CANDIDATE 有效,nLogicChannel必须为1
      int      nNumFace;    // 0 表示没有人脸信息
      int      nNumFaceMax; 
      THID_ATM2G3_FACEInfo *face;

      // 图像
      //int nNumImage;
      THID_ATM2G3_ImageInfo *pImage[MAX_IMAGE_NUM_ATM2G3];
      THID_ATM2G3_ImageInfo *pImage_Reserve[2];  // 参考帧等其他图像:0/1对应两个ATM

      int      nMaxChanNum;
      // 报警视频(预录)
      int nWarnVideoPackageIndex; 
      unsigned char *GetChannelVideoPackageBuffer(int nLogicChannel, int *nBufferSize, int *nVideoPackageIndex) // 用于获取报警事件对应的视频帧(一个数据包)
      {
       if(nLogicChannel>=0 && nLogicChannel<=3 &&
        (nEvtType==THID_ATM2G3_Warning_VIDEO || nEvtType==THID_ATM2G3_Warning_VIDEOSTOP))
       {
        *nBufferSize = pImage[nLogicChannel]->nImageSize;
        *nVideoPackageIndex = nWarnVideoPackageIndex;
        return pImage[nLogicChannel]->pBuffer;
       }
       else
       {
        *nVideoPackageIndex = -1;
        *nBufferSize = 0;
        return 0;
       }
      }

      THID_ATM2G3_Result(void)
      {
       nLogicChannel = -1;
       nEvtType = THID_ATM2G3_Warning_NONE;

       nNumFaceMax = MAX_UNIT_NUM_ATM;
       face = new THID_ATM2G3_FACEInfo[nNumFaceMax];
       nNumFace = 0;

       nNumWarnMax = MAX_UNIT_NUM_ATM;
       region = new THID_ATM2G3_RegionInfo[nNumWarnMax];
       nNumWarn = 0;

       pImage[0] = new THID_ATM2G3_ImageInfo;
       pImage[1] = new THID_ATM2G3_ImageInfo;
       pImage[2] = new THID_ATM2G3_ImageInfo;
       pImage[3] = new THID_ATM2G3_ImageInfo;
       pImage_Reserve[0] = new THID_ATM2G3_ImageInfo;
       pImage_Reserve[1] = new THID_ATM2G3_ImageInfo;

       nMaxChanNum = 4;
       nWarnVideoPackageIndex = 0;
       InitializeCriticalSection(&cs);
      }
      void ResetBuffer(int nFaceBuf, int nRegionBuf, int nFaceCamouflageBuf) // 指定-1不作修改
      {
       if(nFaceBuf>0)
       {
        delete []face;
        face = new THID_ATM2G3_FACEInfo[nFaceBuf];
        nNumFaceMax = nFaceBuf;
        nNumFace = 0;
       }
       if(nRegionBuf>0)
       {
        delete []region;
        region = new THID_ATM2G3_RegionInfo[nRegionBuf];
        nNumWarnMax = nRegionBuf;
        nNumWarn = 0;
       }
      }
      void ResetData() // 接收数据前,清零处理,但不改变buffer大小
      {
       time = 0;
    //   nLinkageExt = 0;
       nEvtType = THID_ATM2G3_Warning_NONE;
       nNumFace = 0;
       nNumWarn = 0;
       pImage[0]->bImageAvailable = 0;
       pImage[0]->nImageSize = 0;
       pImage[1]->bImageAvailable = 0;
       pImage[1]->nImageSize = 0;
       pImage[2]->bImageAvailable = 0;
       pImage[2]->nImageSize = 0;
       pImage[3]->bImageAvailable = 0;
       pImage[3]->nImageSize = 0;
       pImage_Reserve[0]->bImageAvailable = 0;
       pImage_Reserve[0]->nImageSize = 0;
       pImage_Reserve[1]->bImageAvailable = 0;
       pImage_Reserve[1]->nImageSize = 0;

       nWarnVideoPackageIndex = 0;
       nMaxChanNum = 4;
      }
      void Lock() 
      {
       EnterCriticalSection(&cs);
      }
      void UnLock() 
      {
       LeaveCriticalSection(&cs);
      }
      ~THID_ATM2G3_Result()
      {
       EnterCriticalSection(&cs);
       delete[] region;
       region = NULL;
       delete[] face;
       face = NULL;
       delete pImage[0];
       pImage[0] = NULL;
       delete pImage[1];
       pImage[1] = NULL;
       delete pImage[2];
       pImage[2] = NULL;
       delete pImage[3];
       pImage[3] = NULL;
       delete pImage_Reserve[0];
       pImage_Reserve[0] = NULL;
       delete pImage_Reserve[1];
       pImage_Reserve[1] = NULL;
       LeaveCriticalSection(&cs);
       DeleteCriticalSection(&cs);
      }
     }THID_ATM2G3_Result;

    哪位高手帮忙转成c#的类或者结构

    2011年4月15日 14:31

全部回复

  • 先给你推荐个网页翻译的,不是很准,你要自己仔细看看,仔细修改下就行了。

                    Code2Code.net: translate C++ to C# or VB.NET

    注意一些关键字的转换,比如这里面CRITICAL_SECTION,就需要重新声明一下。自定义的那些都需要声明一下。Int 就不用了,指针的,可以用intPtr,或者用ref 关键字标注下。

    在这个网站上有详细的解释(P/Invoke

    pinvoke.net: Search Results

    谢谢理解和支持。


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年4月18日 6:32
    版主
  • 这段代码用了 CER (Contrained Execution Region),所以在 C# 里面转换后,要继承 CriticalFinalizationObject 或者加上 [SecurityDemand]。
    Mark Zhou
    2011年4月18日 10:26