NVD视频解码器SDK使用、大华视频解码器SDK使用

最近调用了视频解码器的接口  因为dll是c++编写的 而我在c#中调用  所以有一个结构体中的类型转换一直报错  今天得到高人指点  把问题解决了  发到网上 供有问题的同胞参考(我之前在网上找了很多  没有一个是真正正确的) 

c++中的声明方式(SDK说明文档提供)

struct DEV_ENCODER_INFO{
  char   szDevIp[DH_MAX_IPADDR_LEN];
  WORD   wDevPort;
  BYTE   bDevChnEnable;
  BYTE   byDecoderID;
  char   szDevUser[DH_USER_NAME_LENGTH_EX];
  char   szDevPwd[DH_USER_PSW_LENGTH_EX];
  int    nDevChannel;
  int    nStreamType;
  BYTE   byConnType;
  BYTE   byWorkMode;
  WORD   wListenPort;
  DWORD  dwProtoType;
  char   szDevName[64];
  BYTE   byVideoInType;
  char   szDevIpEx[DH_MAX_IPADDR_OR_DOMAIN_LEN];
  BYTE   bySnapMode;
  BYTE   byManuFactory;
  BYTE   byDeviceType;
  BYTE   byDecodePolicy;
  BYTE   bReserved[3];
  DWORD  dwHttpPort;
  DWORD  dwRtspPort;
  char   szChnName[32];
  char   reserved[4];
};

 

c#中声明的方式

public struct DEV_DECODER_INFO
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
        public byte[] szDecType;
        public Int32 nMonitorNum;
        public Int32 nEncoderNum;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] szSplitMode;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
        public byte[] bMonitorEnable;
        public byte bTVTipDisplay;          // 指示是否支持TV提示信息叠加设置, 0:不支持 1:支持.
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
        public byte[] reserved1;
      
  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
        public byte[] byLayoutEnable;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
        public byte[] reserved;
    }

使用结构体时

              DEV_ENCODER_INFO lpencoder_info = new DEV_ENCODER_INFO();
                    lpencoder_info.byDecoderID = (byte)decoderID;

                                 //这块必须给变量赋一个长度

                    lpencoder_info.szDevIpEx = new byte[64];
                    lpencoder_info.szDevPwd = new byte[16];
                    lpencoder_info.szDevUser = new byte[16];
                    lpencoder_info.wDevPort = 37777;
                    lpencoder_info.nDevChannel = 1; //通道 
                    lpencoder_info.nStreamType = 0; //主码流
                    lpencoder_info.bDevChnEnable = 1;
                    lpencoder_info.byConnType = 0; //TCP
                    lpencoder_info.byWorkMode = 0; //直连

                   //给予byte[]数组类型的数据赋值

                    System.Text.Encoding.Default.GetBytes("192.168.1.1").CopyTo(lpencoder_info.szDevIpEx, 0);
                    System.Text.Encoding.Default.GetBytes("admin").CopyTo(lpencoder_info.szDevPwd, 0);
                    System.Text.Encoding.Default.GetBytes("admin").CopyTo(lpencoder_info.szDevUser, 0);

            经测试  无异常 

你可能感兴趣的:(Winform)