Includes the write and read functions. the file is automatically created if it does not exist during write. if the corresponding key already exists, its value is automatically overwritten. if the corresponding file does not exist or the key name does not exist, an empty value is returned. very convenient ^_^
Copy codeThe Code is as follows: // System Interface Class
Public static class WinAPI
{
[DllImport ("kernel32")] // interface for writing configuration files
Private static extern long WritePrivateProfileString (
String section, string key, string val, string filePath );
[DllImport ("kernel32")] // interface for reading configuration files
Private static extern int GetPrivateProfileString (
String section, string key, string def,
StringBuilder retVal, int size, string filePath );
// Write the value to the configuration file
Public static void ProfileWriteValue (
String section, string key, string value, string path)
{
WritePrivateProfileString (section, key, value, path );
}
// Read the value of the configuration file
Public static string ProfileReadValue (
String section, string key, string path)
{
StringBuilder sb = new StringBuilder (255 );
GetPrivateProfileString (section, key, "", sb, 255, path );
Return sb. ToString (). Trim ();
}
}