Link to home
Start Free TrialLog in
Avatar of smallee
smallee

asked on

Read and write ini file in PPC

Experts

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!
Avatar of ho_alan
ho_alan

try this
se the CIniFile class
http://www.pocketpcdn.com/articles/samples/IniEdit.zip

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:


[Section]
Entry=Value


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!

ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial