We help IT Professionals succeed at work.

Creation of INI files in VC++

nimitt
nimitt asked
on
Dear Sir/Madam,
         How can I create my own ini file by VC++ code?I want create ny 1 own ini file and then write certain information in that.So how can I doi this?Which class and functions are there in VC++ for this purpose?
Thank you in advance.
                              Nimitt.
Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
Have a look at ReadPrivateProfileString and associated functions.

ps. Microsoft recommend you use the registry.  Maybe a future version of VC++ will pull support of ini files away completely?
CERTIFIED EXPERT
Commented:
Hi nimitt,

you can use (and I think what AndyAinscow meant is) WritePrivateProfileString
and GetPrivateProfileString to write/read strings to/from an ini-file which will
be created if not existing with WritePrivateProfileString.

BTW, it's preferred to use registry in Win32...

hope that helps,

ZOPPO

Commented:
Hi,
 If you are using MFC you can use the following functions of CWinApp derived class.

 * SetRegistryKey()
 * WriteProfileInt()
 * WriteProfileString()
 * GetProfileInt()
 * GetProfileString()

    Now the applications store the data in the windows registry instead of .ini files. If you do not use call to SetRegistryKey("Application name") then your data will be stored in .ini files.
-PK


 

Commented:
The CWinApp class has a member m_pszProfileName witch contains the path of the app's .ini file.
To read and write form the file use the folowing functions:
GetProfileInt
WriteProfileInt
GetProfileString
WriteProfileString
witch are also members of CWinApp class.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Zoppo

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.