Read and write ini file in PPC

Posted on 2005-03-07
Medium Priority
Last Modified: 2008-01-09

I am using embedded visual C++ 4.0.
i want to use a ini file to store the setting of my program in PPC. How can i do it?

Many thanks!
Question by:smallee
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 13476356
try this
se the CIniFile class

The CIniFile Class
Ini files are managed by objects of the CIniFile class (see sample code). Information is serialized on a standard Unicode text file (Unicode header is required) and has the following general format:


Sections are unique on an ini file and entries are unique in a section. Both section and entry names are case sensitive. The value can be any string up to the end of line. There is no limit on the size of strings. No comments are supported on this version.

Objects are created through the constructor CIniFile::CIniFile(LPCTSTR pszFile = NULL). If you supply a file name onthe constructor, the file will be loaded immediately. Otherwise, you can load it by calling BOOL CIniFile::Load(LPCTSTR pszFile = NULL). When you are done using the ini file, you can call BOOL CIniFile::Save(LPCTSTR pszFile = NULL) filling in the file name if the file was not loaded or created empty. If the file was loaded or created with a name, the destructor will save it for you.

Setting and retrieving values is achieved through the Get and Set family methods. These have a consistent signature:

BOOL Get(LPCTSTR pszSection, LPCTSTR pszEntry, CString &strValue);
BOOL Set(LPCTSTR pszSection, LPCTSTR pszEntry, const CString &strValue);

You have to provide the section name, entry name and the value as the last argument. These methods can be extended to support any type you require. In this implementation, I provide two other types just to illustrate the implementation.

BOOL Get(LPCTSTR pszSection, LPCTSTR pszEntry, int &nVal);
BOOL Set(LPCTSTR pszSection, LPCTSTR pszEntry, int nVal);
BOOL Set(LPCTSTR pszSection, LPCTSTR pszEntry, COLORREF rgb);
BOOL Get(LPCTSTR pszSection, LPCTSTR pszEntry, COLORREF &rgb);

Please study their implementations before implementing your own types.

All methods return a BOOL value that reflects the success status of the operation. The Set methods will create both section and entry if these do not exist. Once again, remember about case sensitivity!


Accepted Solution

ee_ai_construct earned 0 total points
ID: 13477733
Question close reversed.   Point passing.
500 Points Forfeit

ai, cs admin

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question