Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI MFC VC++
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 9-May-13 1:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
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++).
 
Regards,
Ian.
  Permalink  
v2
Comments
p.uday kishore at 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 at 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 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2014
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