using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace IFile
{
public class TiniFiles
{
// переопределяемые методы чтения
//№1
[DllImport ("kernel32")]
static extern int GetPrivateProfileString (string Section, string Key,
string Value, StringBuilder Result, int Size, string FileName);
//№2
[DllImport ("kernel32")]
static extern int GetPrivateProfileString (string Section, int Key,
string Value, [MarshalAs (UnmanagedType.LPArray)] byte[] Result,
int Size, string FileName);
//№3
[DllImport ("kernel32")]
static extern int GetPrivateProfileString (int Section, string Key,
string Value, [MarshalAs (UnmanagedType.LPArray)] byte[] Result,
int Size, string FileName);
//Метод записи
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
//Путь до ини файла
public string path;
public TiniFiles(string INIPath)
{
path = INIPath;
}
//Обернутый метод чтения
public object GetEntryValue(string section, string entry)
{
for (int maxsize = 250; true; maxsize *= 2)
{
StringBuilder result = new StringBuilder(maxsize);
int size = GetPrivateProfileString(section, entry, "",result, maxsize, path);
if (size < maxsize - 1)
{
// Returns the value gathered from the EntryKey
return result.ToString();
}
}
}
//Обернутый метод записи
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
}
}