WEB开发网
开发学院软件开发C语言 C# 视频监控系列(15):总结贴——可能用到的C# Wi... 阅读

C# 视频监控系列(15):总结贴——可能用到的C# WinForm技术小结

 2009-04-08 08:25:34 来源:WEB开发网   
核心提示:正文 1. IntPtr转换成byte[] public byte[] ConvertToBytes(IntPtr dataBuf, int length) { byte[] byteBuf = new byte[length]; Marshal.Copy(dataBuf, byteBuf, 0, length); r

正文

1.     IntPtr转换成byte[]

        public byte[] ConvertToBytes(IntPtr dataBuf, int length)
        {
            byte[] byteBuf = new byte[length];
            Marshal.Copy(dataBuf, byteBuf, 0, length);
            return byteBuf;
        }

2.     读写INI文件

一般用于读写配置文件

    /// <summary>
    /// 读写INI文件
    /// </summary>
    public class IniFile
    {
        /// <summary>
        /// 文件INI名称
        /// </summary>
        public string Path;

        /// <summary>
        /// 声明读写INI文件的API函数
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="val"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);


        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        /// <summary>
        /// 类的构造函数,传递INI文件名
        /// </summary>
        /// <param name="inipath"></param>
        public IniFile(string inipath)
        {
            //
            // TODO: Add constructor logic here
            //
            Path = inipath;
        }

        /// <summary>
        /// 写INI文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.Path);

        }

        /// <summary>
        /// 读取INI文件指定
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(5000);
            int i = GetPrivateProfileString(Section, Key, "", temp, 5000, this.Path);
            return temp.ToString();

        }
    }

1 2 3  下一页

Tags:视频监控 系列 总结

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接