函数原型:
LONG __stdcall IP_NET_DVR_GetIPCInfo(LONG index, IPC_ENTRY * pIPCInfo);
C#
[DllImport("NetSDKDLL.dll")]
public static extern UInt32 IP_NET_DVR_GetIPCInfo(UInt32 index, ref IPC_ENTRY pIPCInfo);参数:
Index:要读取的第几个设备(从0开始编号),应该小于IP_NET_DVR_GetSearchIPCCount()返回值
pIPCInfo:信息保存指针#define MAX_IP_NAME_LEN 256
#define MAC_ADDRESS_LEN 256typedef struct
{
char  MACAddress[MAC_ADDRESS_LEN];
int   dhcpEnable;
char  IPAddress[MAX_IP_NAME_LEN];
char  netMask[MAX_IP_NAME_LEN];
char  gateWay[MAX_IP_NAME_LEN];
char  DNS1[MAX_IP_NAME_LEN];
char  DNS2[MAX_IP_NAME_LEN];
}LANConfig;typedef struct
{
int auth;
int videoPort;
int rtpoverrtsp;//added by johnnyling 20090323
int ptzPort;
int webPort;
}StreamAccessConfig;#define GROUP_NAME_MAX_LEN 32
#define ACCOUNT_STATUS_MAX_LEN 8
#define ACCOUNT_NAME_MAX_LEN 40
#define ACCOUNT_PASSWORD_MAX_LEN  40
#define MAX_ACCOUNT_COUNT 20typedef struct
{
char  userName[ACCOUNT_NAME_MAX_LEN];
char  password[ACCOUNT_PASSWORD_MAX_LEN];
char  group[GROUP_NAME_MAX_LEN];
char    status[ACCOUNT_STATUS_MAX_LEN];
}UserAccount;typedef struct
{
int count;
UserAccount accounts[MAX_ACCOUNT_COUNT];
}UserConfig;#define MAX_IPC_SERIALNUMBER 32
#define MAX_DEVICETYPE_LEN 32typedef struct
{
char ipc_sn[MAX_IPC_SERIALNUMBER];
char deviceType[MAX_DEVICETYPE_LEN];
UserConfig userCfg;
StreamAccessConfig streamCfg;
LANConfig lanCfg;
}IPC_ENTRY;c#
[StructLayout(LayoutKind.Sequential)]
    public class LANConfig
    {
        static int MAC_ADDRESS_LEN = 256;
        static int MAX_IP_NAME_LEN = 256;
        public char[] MACAddress = new char[MAC_ADDRESS_LEN];
        public int dhcpEnable;
        public char[] IPAddress = new char[MAX_IP_NAME_LEN];
        public char[] netMask = new char[MAX_IP_NAME_LEN];
        public char[] gateWay = new char[MAX_IP_NAME_LEN];
        public char[] DNS1 = new char[MAX_IP_NAME_LEN];
        public char[] DNS2 = new char[MAX_IP_NAME_LEN];
    }    [StructLayout(LayoutKind.Sequential)]
    public class StreamAccessConfig
    {
        public int auth;
        public int videoPort;
        public int rtpoverrtsp;//added by johnnyling 20090323
        public int ptzPort;
        public int webPort;
    }    [StructLayout(LayoutKind.Sequential)]
    public class UserAccount
    {
        static int GROUP_NAME_MAX_LEN = 32;
        static int ACCOUNT_STATUS_MAX_LEN = 8;
        static int ACCOUNT_NAME_MAX_LEN = 40;
        static int ACCOUNT_PASSWORD_MAX_LEN = 40;
        static int MAX_ACCOUNT_COUNT = 20;        public char[] userName = new char[ACCOUNT_NAME_MAX_LEN];
        public char[] password = new char[ACCOUNT_PASSWORD_MAX_LEN];
        public char[] group = new char[GROUP_NAME_MAX_LEN];
        public char[] status = new char[ACCOUNT_STATUS_MAX_LEN];
    }    [StructLayout(LayoutKind.Sequential)]
    public class UserConfig
    {
        static int MAX_ACCOUNT_COUNT = 20;
        public int count;
        public UserAccount[] accounts = new UserAccount[MAX_ACCOUNT_COUNT];
    }    [StructLayout(LayoutKind.Sequential)]
    public class IPC_ENTRY
    {
        static int MAX_IPC_SERIALNUMBER = 32;
        static int MAX_DEVICETYPE_LEN = 32;
        public char[] ipc_sn = new char[MAX_IPC_SERIALNUMBER];
        public char[] deviceType = new char[MAX_DEVICETYPE_LEN];
        public UserConfig userCfg;
        public StreamAccessConfig streamCfg;
        public LANConfig lanCfg;
    }c#调用
IPC_ENTRY ipc = new IPC_ENTRY();
UInt32 lret = Class1.IP_NET_DVR_GetIPCInfo(i, ref ipc);就报错了 求解答,在线等

解决方案 »

  1.   

    字段用 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]之类的标识长度,去掉按几个static字段,如    public struct Logon
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public String UserName;        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
            public byte[] Passwd;        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
            public byte[] Hash;
        }