C++ DLL方法(参数) 转化为C# 示例

来源:互联网 发布:淘宝潮女装店铺排行榜 编辑:程序博客网 时间:2024/06/05 21:53
1.

 c++:

ITE_HANDLE ITE_AddCamera(IPNC_Info &pInfo,PFSnapPic pfCallback,DWORD dwWait,         void *pContext = NULL);

c#:

           [DllImport("IPNCNetSDK11.dll", EntryPoint = "ITE_AddCamera_IP")]
        public static extern int ITE_AddCameraIP(string szIP, PFSnapPic pfCallback,int dwWait, IntPtr pContext);

   [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
   public delegate void PFSnapPic(IntPtr pBuff, int nLen, ref IPNC_SnapPicInfo pSnapPicInfo, IntPtr pContext);

返回的结构体解析必须按照顺序,但不必所有的都得写。

   handle = util.AddCameraIP(strip,SnapPic, 1000, IntPtr.Zero);
            if (handle == -1)
            {
                MessageBox.Show("添加相机失败");
                return;
            }
            else
            {
                MessageBox.Show("添加相机成功");
            }

        voidSnapPic(IntPtr pBuff,int nLen, ref IPNC_SnapPicInfo pSnapPicInfo, IntPtr pContext)
        {
         
  byte[] p = new byte[nLen];
            System.Runtime.InteropServices.Marshal.Copy(pBuff, p, 0, nLen);

            
            string path;
            path = "D:\\snap" + pSnapPicInfo.SnapTime.wYear.ToString() + pSnapPicInfo.SnapTime.wMonth.ToString()
                + pSnapPicInfo.SnapTime.wDay.ToString() + pSnapPicInfo.SnapTime.wHour.ToString()
                + pSnapPicInfo.SnapTime.wMinute.ToString() + pSnapPicInfo.SnapTime.wSecond.ToString()
                + pSnapPicInfo.SnapTime.wMilliseconds.ToString() + ".jpg";


            FileStream fs = new FileStream(path, FileMode.Create);
            fs.Write(p, 0, nLen);
            fs.Flush();
            fs.Close();
            MessageBox.Show("抓拍到一张图片保存在D盘");


            return;
        }

public struct IPNC_SnapPicInfo
   {
       public int hCamera;


       public ESnapType SnapType;


       public SYSTEMTIME SnapTime;


       public int RedLampTime;


       public int SnapIndex;


       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
       public string Suffix;


       public int TriIndex;


       public int DriveWay;


       public int nSpeed;


       public int nSpeedMax;


       public int nCoilTime;


       public int nCoilDis;


       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
       public string cCarMum;


       public int nWorkMode;


       public int nTD1;


       public int nTD2;


       public int nBrightAVG;


       public SYSTEMTIME Red_Time;


       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
       public string szColor;


       public int nReliability;


       public int nSnapIndex;


       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
       public string szReverve;


       public int picFlag;


       [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
       public int[] nRev;
   }



对应文档说明:

功  能:添加指定IP摄像机

参 数:pInfo  ITE_SearchCamera 搜索返回的摄像机信息

参  数:pfCallback 触发抓拍图片回调函数(软触发和IO触发)

参  数:dwWait等待时间(单位ms)。

参  数:pContext   传入一个上下文,在非软触发时抓拍图片的回调函数中返回该参数。

返回值:成功返回该摄像机在SDK中句柄ITE_HANDLE

 失败返回INVALID_ITE_HANDLE(-1)。

说明:操作摄像机前必须先成功添加摄像机到SDK并保存返回的句柄。

回调函数

原 型: void (*PFSnapPic) (char* const pBuff,

  int nLen,

  IPNC_SnapPicInfo* pSnapPicInfo,

  void* pContext);

功 能:对选中摄像机显示图像进行瞬间抓图

参 数:pBuff图片信息接收缓冲区。

nLen图片大小。

SnapPicInfo返回图片附加信息。 

pContext抓拍图片上下文。

返回值:成功返回 RET_OK,nLen返回实际接收到的图片大小。

 失败返回 RET_ERR。

说  明:该函数中用户应该把图片数据、图片信息和上下文拷贝到用户缓冲区,马上返回, 

然后在用户自己的线程中处理图片数据

相关结构定义:

//抓拍图片附加信息

typedef  struct IPNC_SnapPicInfo

{

ITE_HANDLEhCamera;//摄像机句柄

ESnapTypeSnapType;//抓拍类型

IPNC_TIMESnapTime;//图片曝光时间

DWORDRedLampTime;//图片曝光时红灯时间,单位1/10秒

intSnapIndex;//抓拍序号

charSuffix[4];//抓拍文件名后缀

intTriIndex;//条件索引号

intDriveWay;//车道信息

intnSpeed;//速度

intnSpeedMax;//限速

intnCoilTime;//线圈时间差(单位:ms)

intnCoilDis;//线圈距离(单位:cm)

charcCarMum[16];//车牌号码

intnWorkMode;//摄像机工作模式(0:白天 1:夜间)  该变量对DM368有//效,S系列相机无效

intnTD1;//抓拍延时(单位us)该变量对DM368有效,S系列相机无

intnTD2;//曝光延时(单位us)该变量对DM368有效,S系列相机无效

intnBrightAVG;//平均亮度

IPNC_TIMERed_Time;//红灯开始时间

charszColor[8];//车牌颜色  T系列相机有效

intnReliability;//可信度

intnSnapIndex;//图片序号

charszReverve[4];//保留(X)

intpicFlag;//最高位:为1该值有效,0无效, 最后一位: 1为SD卡图//片上传,0即时抓拍图片上传,其余位未用。

unsigned shortcardsLeft;//车牌左T系列相机有效

unsigned shortcardsTop;//车牌上T系列相机有效

unsigned shortcardsRight;//车牌右T系列相机有效

unsigned shortcardsBottom;//车牌下T系列相机有效

trafficTypeeILL;//违法类型K系列相机有效

shortnGroupSnapCount;//每组抓拍张数K系列相机有效

shortnRev1;//保留,字节对齐

Optional_PicAlgHeader*pAlgOut;//算法输出结果,指针为固定地址,后一张图片的数据覆盖前一张图片的数据K系列相机有效

int CarGroupNO; //车辆统计(抓拍组数),从开始判断是否是一次抓拍出的图片K系列相机有效

int nRev; //保留

}IPNC_SnapPicInfo,*PIPNC_SnapPicInfo;

 

typedef enum

{

eSoft, //软触发

ebayonet, //卡口

eRedlight, //闯红

eRS485,  //RS485触发

eRS232, //RS232雷达触发

eSpeed, //超速触发

eStream //流

}ESnapType;


2.

原 型:int ITE_SnapPicture(ITE_HANDLE hCamera,void* pContext,DWORD dwWait);

功 能:对选中摄像机显示图像进行瞬间抓图(抓拍一张)

参 数:hCamera 为要控制抓拍的摄像机句柄。

pContext 抓拍图片接收上下文,在回调函数里返回上下文。

dwWait 抓拍到图片接收完成等待的时间。

返回值:成功返回 RET_OK, 

 失败返回 RET_ERR。

c#:publicstatic externint ITE_SnapPicture(int hCamera, IntPtr pContext,int dwWait);


0 0
原创粉丝点击