MP4_ServerStart 一直启动失败,返回False,尝试了n种方法,最后修改了struct才成功。

 

原函数:

 

BOOL __stdcall MP4_ServerStart(PSERVER_VIDEOINFO videoinfo);

 

typedef struct{
BYTE m_datatype[64];//通道数据类型,是否支持电话线连接
BYTE m_channum; //系统的通道个数
DWORD m_waittime; //超时等待时间,1-300,单位:分钟
DWORD m_bufnum; //目前没有使用
}SERVER_VIDEOINFO, *PSERVER_VIDEOINFO;

 

C#封装:

 

        [DllImport("HikServer.dll")]
        public static extern bool MP4_ServerStart(ref PSERVER_VIDEOINFO videoinfo);

 

    [StructLayout(LayoutKind.Sequential)]
    public struct PSERVER_VIDEOINFO
    {
        public IntPtr m_datatype;  //序列号 
        public byte m_channum;//系统的通道个数
        public int m_waittime;//超时等待时间,1-300单位:分钟
        public int m_bufnum;//目前没有使用
    }

 

调用:

 

    PSERVER_VIDEOINFO info = new PSERVER_VIDEOINFO();

            byte[] m_datatype = new byte[64];

            for (int i = 0; i < 4; i++)
            {
                m_datatype[i] = 50;
            }

            m_datatype[0] = 52;

            IntPtr ptr = Marshal.AllocCoTaskMem(64);

            Marshal.Copy(m_datatype, 0, ptr, 64);

            info.m_datatype = ptr;

            info.m_channum = (byte)4;

            info.m_waittime = 2;

            builder.AppendLine("MP4_ServerStart");

            builder.AppendLine(HikServer.MP4_ServerStart(ref info).ToString());

 

 

参考文献:

http://topic.csdn.net/t/20060727/21/4910175.html

 

posted on 2008-10-26 19:53  大城小格  阅读(891)  评论(0编辑  收藏  举报