Skip to content

Instantly share code, notes, and snippets.

@RobertMischke
Created December 13, 2012 19:23
Show Gist options
  • Save RobertMischke/4278997 to your computer and use it in GitHub Desktop.
Save RobertMischke/4278997 to your computer and use it in GitHub Desktop.
public class IniFile
{
public string Path;
[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)
{
Path = iniPath;
}
public void WriteValue(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, Path);
}
public string ReadValue(string section, string key)
{
var sb = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", sb, 255, Path);
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment