Click here to Skip to main content
13,006,195 members (78,316 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I need to save some data from a dialog like height and width but i don't know to how to do it using ReadPrivateProfileString and writePrivateProfileString.

can i get any example regarding this or any article how to save the settings in INI file.

Posted 9-May-13 0:00am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi Uday,
First of all, as far as I'm aware there is no such function as ReadPrivateProfileString. The function is GetPrivateProfileString.

Secondly, both that function and WritePrivateProfileString, as MSDN says, are "provided only for compatibility with 16-bit Windows-based applications." I cannot believe you are developing for 16-bit, so you should not be using these functions!

As MSDN says, "Applications should store initialization information in the registry."
Read about RegSetValueEx and RegGetValue.

Alternatively, use an XML file like C# config files use (although, granted, that would be more work in C++).

p.uday kishore 9-May-13 7:05am
so is there any other way to work with.requirement is to use INI u have any idea how to create that using mfc/c++???
Ian A Davidson 9-May-13 7:46am
Take a look here:

There's a link there that points to an interesting looking project on CodeProject itself:

I may have been a bit hasty in saying that you should not ever use those functions (as someone on that first forum page points out, the functions will probably never disappear). However, it is clear that even if using ini files through those functions, there is some interaction with the registry (it seems they look in the registry first!) therefore they can't be the most efficient. You are better off either using the registry directly as suggested, or writing the file youself.

If it really must be an "INI" format file, then perhaps try looking that CIniFile, linked above. However, if it is simply a case of needing to save a couple of values in some sort of initialisation file which needs to be modifiable by a user, then you could simply write them as a couple of values in a plain text file (and give it a generic extension, such as ".dat"), or define your own format, or use a well structured and documented specification like XML.

p.uday kishore 9-May-13 8:35am
as normal text file i tried but they need the format like sections and keys so am thinking to move on to that way of design.that's y

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100