Last active
August 14, 2018 02:13
-
-
Save josuebasurto/5109215 to your computer and use it in GitHub Desktop.
Class to save and read from a INI File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright Josue Basurto 2013 | @josuebasurto | http://josuebasurto.com */ | |
using System.Runtime.InteropServices; | |
using System.Text; | |
namespace customnamespace | |
{ | |
internal class INIHelper | |
{ | |
#region Variables y constantes | |
public string path; | |
private const int K_TAMANO = 255; | |
#endregion | |
#region Llamadas a kernel32 | |
[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); | |
#endregion | |
#region Constructor | |
public IniFile(string PathArchivo) | |
{ | |
path = PathArchivo; | |
} | |
#endregion | |
#region Metodos Expuestos | |
public void IniWriteValue(string Seccion, string Llave, string Valor) | |
{ | |
WritePrivateProfileString(Seccion, Llave, Valor, this.path); | |
} | |
public string IniReadValue(string Seccion, string Llave) | |
{ | |
StringBuilder stringTemporal = new StringBuilder(255); | |
int i = GetPrivateProfileString(Seccion, Llave, "", stringTemporal, K_TAMANO, this.path); | |
return stringTemporal.ToString(); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment