Click here to Skip to main content
12,698,179 members (23,472 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked


, 7 Sep 2005
Rate this:
Please Sign up or sign in to vote.
Serialize and access your application's config values.

Sorry, it should have been SimpleConfig.jpg


To increase an application's usability it is often a good idea to deal with some persistent information. If someone doesn't want to hide these parameters in his Registry (maybe he often modifies these parameters manually), he could use a plain text file instead. The Config class that is presented in this example, offers a complete solution to handle plain text files as config files.


  • common parameter handling
    • <name> = <value>
  • scope names: different config values can have equal names.
    • <scopeA:name> = <value>
    • <scopeB:name> = <value>
  • value lists: indices will be added automatically, if <name> specifies a value array.
    • <name[0]> = <value>
    • <name[1]> = <value>
    • <name[2]> = <value>

The config file

This example deals with:

  • the window's last size and position
  • the filters of the CFileDialog
  • the index of the last used filter
  • the directory of the last opened file

Sorry, it should have been Result.jpg

Using the code


If you include the Config.h header in your StdAfx.h, you will be able to access all your config values from any file that itself includes the StdAfx.h.


Calling all necessary functions to obtain the values from a value list. (Doing this in just one function is a bit hypothetical.)

// should always be the first Config method you call
// (a good place would be within your InitInstance() method)

// read your config file

// the list of all values that are registered to "Foo"
vector<string> values;

// get first config value
const char* value = Config::getValue("Foo");

// get all config values

    value = Config::getNextValue();

// write your config file (and use the path
// that was passed to Config::import())

// should always be the last Config method you call
// (a good place would be within your ExitInstance() method)

Continuative stuff

The outright interface is a bit more extensive. Please have a look at the source code or the available documentation.

Other classes

  • ConfigValue

    This class implements just some conversion constructors. Each constructor converts its passed value to const char*. All implicit type conversion that is done for you is encoded in this class. Due to this class the Config class only needs to provide one kind of setValue() method.

  • Config::Implementation

    You don't have to worry about this class. This class holds all algorithms and data structures that enable the provided functionality. I separated this class from the Config class to be able to kick out all include directives from the Config.h file.


Version 1.0


  • Config handling
    • initialize()
    • depose()
    • import()
    • export()
    • enterScope()
    • leaveScope()
    • setValue()
    • addValue()
    • getValue()
    • getNextValue()
    • removeValue()
    • removeParameter()
  • Implicit type conversion
    • ConfigValue(int)
    • ConfigValue(long)
    • ConfigValue(unsigned long)
    • ConfigValue(double)
    • ConfigValue(bool)
    • ConfigValue(char)
    • ConfigValue(char*)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Achim Klein
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWhy not use INI files? Pin
milkplus19-Nov-09 11:23
membermilkplus19-Nov-09 11:23 
QuestionSome comments Pin
Johann Gerell12-Sep-05 14:44
memberJohann Gerell12-Sep-05 14:44 
AnswerRe: Some comments Pin
Achim Klein13-Sep-05 3:06
memberAchim Klein13-Sep-05 3:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 7 Sep 2005
Article Copyright 2005 by Achim Klein
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid