The Windows API itself has written a function of operating INI, but sometimes it may not be very convenient. Package these APIs will make great convenience we read and write the INI file.
Online INI is more like a cattle. But I personally think that there is no need to do every INI operation really call the functions in the INI class. Let's take a look at the CINI class that I have written to use Inline and C but parameter constructs:
/ / Prerequisite #pragma once # include
#define INI_MAIN TEXT ("main")
// CINI class class cini {public: // INI file name tchar m_tzfilename [max_path];
PUBLIC: // Initialization Profile INline Cini () {getModuleFileName (Null, M_TZFileName, Max_Path); LSTRCPY (M_TZFileName Lstrlen (M_TZFileName) - 4, Text (". ini"));}
// Initialization Profile Inline Cini (PCTSTR PTZFileName) {lstrcpy (m_tzfilename, ptzfilename);}
// Get an integer of inline UINT GetInt (PCTSTR ptzKeyName, INT iDefault = 0, PCTSTR ptzSectionName = INI_Main) {return GetPrivateProfileInt (ptzSectionName, ptzKeyName, iDefault, m_tzFileName);}
// Set integer inline Bool Setint (PCTSTR PTZKEYNAME, INT IVALUE = 0, PCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTRING [16];
WSPrintf (Tzstring, Text ("% D"), iValue; Return WritePrivateProfileString (ptzsectionname, ptzkeyname, tzstring, m_tzfilename);}
// Get string inline DWORD GetString (PCTSTR ptzKeyName, PTSTR ptzReturnedString, DWORD dwSize = MAX_PATH, PCTSTR ptzDefault = NULL, PCTSTR ptzSectionName = INI_Main) {return GetPrivateProfileString (ptzSectionName, ptzKeyName, ptzDefault, ptzReturnedString, dwSize, m_tzFileName);}
// set the string inline BOOL SetString (PCTSTR ptzKeyName, PCTSTR ptzString = NULL, PCTSTR ptzSectionName = INI_Main) {return WritePrivateProfileString (ptzSectionName, ptzKeyName, ptzString, m_tzFileName);}
// Get Structure inline BOOL GetStruct (PCTSTR ptzKeyName, PVOID pvStruct, UINT uSize, PCTSTR ptzSectionName = INI_Main) {return GetPrivateProfileStruct (ptzSectionName, ptzKeyName, pvStruct, uSize, m_tzFileName);} // set the configuration inline BOOL SetStruct (PCTSTR ptzKeyName, PVOID PVSTRUCT, UINT USIZE, PCTSTR PTZSECTIONNAME = INI_MAIN) {Return WritePrivateProfileStruct (ptzsectionname, ptzkeyname, pvstruct, usize, m_tzfilename);}
// Get Section inline DWORD GetSection (PTSTR ptzReturnBuffer, DWORD dwSize, PCTSTR ptzSectionName = INI_Main) {return GetPrivateProfileSection (ptzSectionName, ptzReturnBuffer, dwSize, m_tzFileName);}
// Setting the section inline dword setsection (PCTSTR PTZSTRING, PCTSTR PTZSTRING, PCTSTR PTZSECTIONNAME = INI_MAIN) {Return WritePrivateProfilesection (ptzsectionname, ptzstring, m_tzfilename);}
// Get the Name Inline Dword GetSecionNames (PTSTR PTZRETURNBuffer, DWORD DWSIZE) {Return GetPrivateProfileeSectionNames (ptzreturnbuffer, dwsize, m_tzfilename);}};
An INI file is a CINI object. For example, the use is as follows:
CINI INIMAIN; // Using the default INI name, that is, the extension is simplified in the extension.
CINI INISEL (Text ("f: //sel.ini")); // Specify the INI path
Tchar Tztext [MAX_PATH];
ColorRef CrtextColor;
CrtextColor = Inimain.Getint (INI_TEXTCOLOR);
InImain.setint (Ini_TextColor, CrtextColor);
InImain.getstring (INI_PICTURESPATH, TZTEXT);
Inimain.setstring (INI_PICTURESPATH, TEXT ("f: // my picture");
INISEL.SETSTRUCT (INI_WINDOWRECT, & RTWINDOW, SIZEOF (RECT));
Of course, if only one INI file is operated in a program, this class can also be changed to a static class (which is very simple as it is preceded before each function and the variable).
Download: Cini