0

I'm developing a c++ win32 application and i would like to implement persistent storage into it. I know I can use filesystem or a database or the registry, but what would be the best way for storing a:

 boolean
 unsigned int
 wchar_t [256]
 boolean [15]

I need to read/write from the storage only when the application starts and shuts down.

This is a user level application and the data should be stored per user. I want to store application preferences (trackbar position, some settings, number of runs,..) so there is no need to import/export settings and troubleshooting.

Which storage method would be the most appropriate for this type of data?

Kara
  • 6,115
  • 16
  • 50
  • 57
blejzz
  • 3,349
  • 4
  • 39
  • 60
  • Need more information.. is this a user-level application? If so, should the data be persistent across all users or is it user-specific? For troubleshooting/support do you need to be able to edit or read the saved data with a text editor? Do you want users to be able to easily move the data to a new computer, or is it tied to one instance? – Steven T. Snyder Sep 25 '11 at 22:04

3 Answers3

4

I think the easiest way to write settings on Windows is to put them in the registry. For user specific settings you will write in the HKEY_CURRENT_USER section. Here is the full list of registry access functions in the Win32 API.

If you consider you will ever need to port your application to other platforms, then you may want to look at a more cross-platform friendly solution. What I do in my apps is to write settings the Unix way, with a settings file in the user's home directory. This has the added benefit that you can use a text based format that you (or your users) can edit if necessary, for example, you could write it in the venerable .ini format using the WritePrivateProfileString or similar API calls. Note that on Windows, applications don't write settings files directly in the home directory, there is the "AppData" user specific folder where these files typically go. You can obtain the path of this folder by calling the SHGetFolderPath function.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
3

The simplest solution is to store the information in a .ini file under the user's APPDATA path.

Community
  • 1
  • 1
Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
0

Consider just serialization/protobuffer: http://code.google.com/p/protobuf/ where you write to some user specific path for the application

loki11
  • 374
  • 1
  • 4