Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.


Regards,
Uday.
Posted

 
Share this answer
 
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++).

Regards,
Ian.
 
Share this answer
 
v2
Comments
P Uday kishore 9-May-13 7:05am    
so is there any other way to work with.requirement is to use INI file.do u have any idea how to create that using mfc/c++???
Ian A Davidson 9-May-13 7:46am    
Take a look here:

http://stackoverflow.com/questions/4279532/methods-of-storing-application-data-settings-without-the-registry


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

http://www.codeproject.com/Articles/12914/INI-Reader-Writer-Class-for-MFC-and-ANSI-C-Windows


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.


Regards,
Ian.
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900