I'm using a really simple c# ini file class.
But when I try to read from my ini file, I always get the default string value.
The ini class:
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace SimChecklist
{
class IniFile
{
[DllImport("kernel32")] private static extern long WritePrivateProfileString(string section,
string key, string value, string iniFilePath);
[DllImport("kernel32")] private static extern int GetPrivateProfileString(string section,
string key, string defValue, StringBuilder retValue, int size, string iniFilePath);
private const int valueLength = 255;
private String iniPath;
public IniFile(String iniFilePath)
{
iniPath = iniFilePath;
}
public void WriteString(String section, String key, String value)
{
WritePrivateProfileString(section, key, value, iniPath);
}
public void WriteInt(String section, String key, int value)
{
WriteString(section, key, value.ToString());
}
public void WriteDouble(String section, String key, Double value)
{
WriteString(section, key, value.ToString());
}
public String ReadString(String section, String key, String defValue)
{
StringBuilder tmp = new StringBuilder(valueLength);
int i = GetPrivateProfileString(section, key, defValue, tmp, valueLength, iniPath);
return tmp.ToString();
}
public int ReadInt(String section, String key, int defValue)
{
return Int32.Parse(ReadString(section, key, defValue.ToString()));
}
public Double ReadDouble(String section, String key, Double defValue)
{
return Double.Parse(ReadString(section, key, defValue.ToString()));
}
}
}
My use in my mainform:
IniFile ini = new IniFile("C:\\Checklist.ini");
string tempString = ini.ReadString("simTheme", "simType", "aaaa");
My ini file:
[simTheme]
simType="FS2004 A Century of Flight"
simTypeMaxLen=32
So, tempString always == "aaaa".
Thank you for any help.