CIniFile | CodeGuru

CIniFile

Environment: VC++ 6.0 All Windows I had to build an application that uses an ini file. When looking in CodeGuru I found Adam Clauss’ class CIniFile. The problem was that it wasn’t very intuitive to work with, so I took his idea of the Sections struct and improved it. I’m using the API functions GetPrivateProfileSectionNames, […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 27, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC++ 6.0 All Windows

I had to build an application that uses an ini file. When looking in CodeGuru I found Adam Clauss’ class CIniFile. The problem was that it wasn’t very intuitive to work with, so I took his idea of the Sections struct and improved it. I’m using the API functions GetPrivateProfileSectionNames, GetPrivateProfileSection, WritePrivateProfileSection, and WritePrivateProfileString. I believe this class is easier to use.

The class has this functions divided by groups and is very easy to use
after creating the object call Open( “c:MyProjectstest.ini”) or by calling SetPath(“c:MyProjectstest.ini”) call Open(). After that it is straightforward. You should note that unless you set DoNotWrite(), when you change something in the ini file the class will write the contents.

// operation on the sections and keys
int DeleteSection( CString strsectionname);
int DeleteKey( CString sectionname,
               CString delkey);
int AddSection( CString sectionname);
int AddSection( CStringArray mKeys,
                CStringArray mValues,
                CString sectionname);
void AddKey( CString sectionname,
             CString keyname,
             CString value);
// operations on the ini file
void SetPath( CString path);
BOOL Open( CString path);
BOOL Open();
BOOL Write();
void Reset();
void Close();
void DoNotWrite();
// getters
CString GetKeyValue( CString sctionname,
                     CString keyname);
int GetSection( CStringArray &mKeys,
                CStringArray &mValues,
                CString sectionname);
CString GetSection( int sectionIndex);
int GetSetionsSize(){return Sections.GetSize();}
int GetKeysSize( CString sectionname);
// setters
int SetKeyValue( CString sectionname,
                 CString keyname,
                 CString value);

Downloads

Download source - 4 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.