using System;
using System.Runtime.InteropServices;
using System.IO;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Core.Mes.Common
{
    public class INIFile
    {
        public string inipath;

        [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);

        public INIFile(string INIPath)
        {
            inipath = INIPath;
        }

        public void WriteValue(string section, string key, string value)
        {
            WritePrivateProfileString(section, key, value, inipath);
        }

        public string ReadValue(string section, string key)
        {
            StringBuilder temp = new StringBuilder(500);
            int length = GetPrivateProfileString(section, key, "", temp, 500, inipath);
            return temp.ToString();
        }
    }
}