1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
namespace MonSoft
{
using System;
using System.Runtime.InteropServices;
using System.Text;
internal class cIni
{
private int li_BufferLen = 0x100;
private string ls_IniFilename;
public cIni(string pIniFilename)
{
this.ls_IniFilename = pIniFilename;
}
[DllImport("kernel32", SetLastError=true)]
private static extern int GetPrivateProfileString(string pSection, string pKey, string pDefault, byte[] prReturn, int pBufferLen, string pFile);
[DllImport("kernel32", SetLastError=true)]
private static extern int GetPrivateProfileStruct(string pSection, string pKey, byte[] prReturn, int pBufferLen, string pFile);
public void ReadSections(ref Array pSections)
{
pSections = this.z_GetString(null, null, null).Split(new char[1]);
}
public string ReadValue(string pSection, string pKey)
{
return this.z_GetString(pSection, pKey, "");
}
public string ReadValue(string pSection, string pKey, string pDefault)
{
return this.z_GetString(pSection, pKey, pDefault);
}
public void ReadValues(string pSection, ref Array pValues)
{
pValues = this.z_GetString(pSection, null, null).Split(new char[1]);
}
public void RemoveSection(string pSection)
{
WritePrivateProfileString(pSection, null, null, this.ls_IniFilename);
}
public void RemoveValue(string pSection, string pKey)
{
WritePrivateProfileString(pSection, pKey, null, this.ls_IniFilename);
}
//----------------- Ici le "ReadSection" manquant que je n'arrive pas à coder
[DllImport("kernel32", SetLastError=true)]
private static extern int WritePrivateProfileString(string pSection, string pKey, string pValue, string pFile);
[DllImport("kernel32", SetLastError=true)]
private static extern int WritePrivateProfileStruct(string pSection, string pKey, string pValue, int pValueLen, string pFile);
public void WriteValue(string pSection, string pKey, string pValue)
{
WritePrivateProfileString(pSection, pKey, pValue, this.ls_IniFilename);
}
private string z_GetString(string pSection, string pKey, string pDefault)
{
string str = pDefault;
byte[] prReturn = new byte[this.li_BufferLen];
int count = GetPrivateProfileString(pSection, pKey, pDefault, prReturn, this.li_BufferLen, this.ls_IniFilename);
return Encoding.GetEncoding(0x4e4).GetString(prReturn, 0, count).TrimEnd(new char[1]);
}
public int BufferLen
{
get
{
return this.li_BufferLen; |
Partager