How to read/write an INI file

30 12 2009

 

 

INI files are plain text files that contain configuration information. Each INI files contains one or more sections and each sections contain zero or more entries. How shall we read an entry from a section or write to a section.

 

 

Read and write operations of an initialization file can be performed bu using the following APIs  GetPrivateProfileString and WritePrivateProfileString respectively.

 

 

Read from INI file

void ReadFromIniFile()
{
   TCHAR szKeyValue[32];
   GetPrivateProfileString(_T("Section 1"), _T("Key 1"), _T("") ,szKeyValue, 32, _T("C:\\test.ini"));
}

 

Write to INI file

void WriteToIniFile()
{
  WritePrivateProfileString(_T("Section 2"), _T("Key 2"), _T("Hello World"), _T("C:\\test.ini"));
}

 

 

Integer value associated with a key in the specified section of an INI file can be retrieved by using the  API GetPrivateProfileInt.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: