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 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


About the Author

Thomas Holte

Born in 1953 I'm a passionate programmer since 30 years. I'm employed as a software developer at a large company in Nuremberg, Germany. My hobbies are programming (what else) and digital photography.

Comments

  • Warning !!!

    Posted by Legacy on 01/06/2002 12:00am

    Originally posted by: Remon

    For Windows NT/2000 or later, calls to private profile functions may be mapped to the registry instead of to the specified initialization files when the initialization file and section are specified in the registry under the following keys: HEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping.

    So when using this class to read C:\WinNT\Win.Ini, the sections & keys returned are read from the registry and won't reflect the real file contents....

    See Micro$oft documentation for more informations.

    Thanks for your contribution
    A++
    R�mon

    Reply
  • Great, but no implemention of WritePrivateProfile*()

    Posted by Legacy on 01/03/2002 12:00am

    Originally posted by: Phips Xue

    It's so great that Thomas encapsolute the functions into a class, but there's no implemention of WritePrivateProfile*().

    ;)

    Reply
  • Yes, but...

    Posted by Legacy on 12/29/2001 12:00am

    Originally posted by: Tiko Gola

    What is your picture for ?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds