MFC extension class CPrivateProfile | CodeGuru

MFC extension class CPrivateProfile

Environment: Visual C++ 6, Windows 95/98/Me/NT/2000/XP The class CPrivateProfile is a wrapper class around the Win32 functions GetPrivateProfileString and GetPrivateProfileInt. It enables an easy way to traverse and read INI files. The allocation and deallocation of needed internal buffers will be managed automatically. You can easily extend the class by write and delete operations. CPrivateProfile […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 28, 2001
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: Visual C++ 6, Windows 95/98/Me/NT/2000/XP

The class CPrivateProfile is a wrapper class around the Win32 functions
GetPrivateProfileString and GetPrivateProfileInt.
It enables an easy way to traverse and read INI files. The allocation and deallocation
of needed internal buffers will be managed automatically. You can easily extend the class
by write and delete operations.

CPrivateProfile class members:




























Constructor:
CPrivateProfile(LPCTSTR pszFileName) Constructs a CPrivateProfile object and assigns to it
the INI file pszFileName.
Public member functions:
int GetInt(LPCTSTR pszSectionName, LPCTSTR pszKeyName, int nDefault = 0) const Retrieves the integer associated with the key pszKeyName in the section
pszSectionName. If the key name cannot be found nDefault will be returned.
LPCTSTR GetNext(POSITION& position) const Returns a pointer to the next section or key name.
position is a reference to a POSITION value returned
by a previous GetNext or GetStartPosition.
POSITION GetStartPosition(LPCTSTR pszSectionName = 0) Returns a POSITION value that indicates a starting position
for iterating a section or key list. If pszSectionName is 0 POSITION
is the starting position of the section list. Otherwise POSITION is the starting
position of the key list associated with the section pszSectionName.
CString GetString(LPCTSTR pszSectionName, LPCTSTR pszKeyName, LPCTSTR pszDefault = _T(“”)) const Retrieves the string associated with the key pszKeyName in the section
pszSectionName. If the key name cannot be found pszDefault will be returned.

Downloads

Download demo project – 50 Kb

Download source – 2 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.