Using system;
Using system. Collections. Generic;
Using system. runtime. interopservices;
Using system. text;
Namespace meidushav1.business
{
Public class inimanager
{
/* prototype
* bool writeprivateprofilestring (
lpctstr lpappname, // It is a field name in the INI file.
lptstr lpkeyname, // It is a key name under lpappname. Generally, it is a variable name.
lpctstr lpstring, // It is the key value, that is, the value of the variable, but it must be of the lpctstr or cstring type.
lpctstr lpfilename // file path
*);
*/
[Dllimport ("Kernel32")]
Private Static extern long writeprivateprofilestring (string section, string key, string Val, string filepath );
/* DWORD getprivateprofilestring (
Lptstr lpappname,
Lptstr lpkeyname,
Lptstr lpdefault, // If the INI file does not contain the field name or key name specified by the first two parameters, this value is assigned to the variable.
Lptstr lpreturnedstring,
DWORD nsize,
Lptstr lpfilename
*);*/
[Dllimport ("Kernel32")]
Private Static extern int getprivateprofilestring (string section, string key, string def, stringbuilder retval, int size, string filepath );
Private string filepath;
Public inimanager (string filepath)
{< br> This. filepath = filepath;
}
Public void write (string section, string key, string value)
{< br> try
{< br> writeprivateprofilestring (section, key, value, filepath);
}< br> catch (exception ex)
{< br> throw new exception (ex. tostring ();
}< BR >}
Public String read (string section, string key)
{
Try
{
Stringbuilder temp = new stringbuilder (255 );
Int I = getprivateprofilestring (section, key, String. Empty, temp, 255, filepath );
Return temp. tostring ();
}
Catch (exception ex)
{
Throw new exception (ex. tostring ());
}
}
}
}
Code
1