Below is some of the very clear examples I collected about using the Win API in C #
Using
System;
Using
System.Text;
Using
System.IO;
Using
System.Runtime.InteropServices;
Namespace
Pubop
{Public class OperateIniFile {API function declaration #region API function declaration [DllImport ( "kernel32")] // return 0 to indicate failure and non-zero for a successful private static extern long WritePrivateProfileString (string section, string key, string val, string filePath) ; [DllImport ( "kernel32")] // returns string buffer length acquired private static extern long GetPrivateProfileString (string section, string key, string def, StringBuilder retVal, int size, string filePath); #endregion read Ini file # Ini file read region public static string ReadIniData (string Section, string Key, string noText, string iniFilePath) {if (File.Exists (iniFilePath)) {StringBuilder temp = new StringBuilder (1024); GetPrivateProfileString (Section, Key, noText, temp , 1024, INIFILEPATH; RETURN TEMP.TOSTRING ();} else {return string.empty;}} #endregion Write INI file #Region Write INI file Public Static B ool WriteIniData (string Section, string Key, string Value, string iniFilePath) {if (File.Exists (iniFilePath)) {long OpStation = WritePrivateProfileString (Section, Key, Value, iniFilePath); if (OpStation == 0) {return false } Else {return true;}} else {return false;}} #ENDREGON}}