You can call two APIs in kernel32.dll: writeprivateprofilestring and getprivateprofilestring to read INI files.
The specific implementation code is as follows:
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using system. runtime. interopservices; // dllimport
Using system. Text; // stringbuilder
Namespace iniprocess
{
Public class form1: system. Windows. Forms. Form
{
Private system. Windows. Forms. textbox textbox1;
Private system. Windows. Forms. Button button2;
Private system. Windows. Forms. Button button1;
[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 );
Public void iniwritevalue (string section, string key, string value, string filepath) // The write operation on the INI file.
{
Writeprivateprofilestring (section, key, value, filepath );
}
Public String inireadvalue (string section, string key, string filepath) // a function for reading an INIFILE
{
Stringbuilder temp = new stringbuilder (255 );
Int I = getprivateprofilestring (section, key, "", temp,
255, filepath );
Return temp. tostring ();
}
Private void button#click (Object sender, system. eventargs E)
{
This. textbox1. Text = inireadvalue ("ODBC 32 bit data sources", "MS Access Database", "E: \ temp \ ODBC. ini ");
}
Private void button2_click (Object sender, system. eventargs E)
{
Iniwritevalue ("ODBC 32 bit data sources", "MS Access Database", this. textbox1. Text, "E: \ temp \ ODBC. ini ");
}
}
}