Using System;
Using System. IO;
Using System. Runtime. InteropServices;
Using System. Text;
Namespace WindowsApplication6
{
/// <Summary>
/// Summary of iniClass.
/// </Summary>
// TODO: add the constructor logic here
Public class INIClass
{
Public string inipath;
[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 );
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "INIPath"> file path </param>
Public INIClass (string INIPath)
{
Inipath = INIPath;
}
/// <Summary>
/// Write the INI File
/// </Summary>
/// <Param name = "Section"> Project name (for example, [TypeName]) </param>
/// <Param name = "Key"> Key </param>
/// <Param name = "Value"> Value </param>
Public void IniWriteValue (string Section, string Key, string Value)
{
WritePrivateProfileString (Section, Key, Value, this. inipath );
}
/// <Summary>
/// Read the INI File
/// </Summary>
/// <Param name = "Section"> Project name (for example, [TypeName]) </param>
/// <Param name = "Key"> Key </param>
Public string IniReadValue (string Section, string Key)
{
StringBuilder temp = new StringBuilder (500 );
Int I =
GetPrivateProfileString (Section, Key, "", temp, 500, this. inipath );
Return temp. ToString ();
}
/// <Summary>
/// Verify whether the file exists
/// </Summary>
/// <Returns> Boolean value </returns>
Public bool ExistINIFile ()
{
Return File. Exists (inipath );
}
}
//
}