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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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!