Click here to Skip to main content
11,704,315 members (54,210 online)
Rate this: bad
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.

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 at 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 at 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 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 740
1 OriginalGriff 520
2 Maciej Los 355
3 Andy Lanng 284
4 CPallini 267
0 OriginalGriff 8,824
1 Sergey Alexandrovich Kryukov 8,247
2 CPallini 5,197
3 Maciej Los 4,726
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2015
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