Re: Reading Ini File
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eH8BCTR0GHA.4116@TK2MSFTNGP02.phx.gbl...
Z.K. <nospam@nospam.net> wrote:
I used GetPrivateProfileSection to read in the keys and their values,
but it only returns the first string. Is there a way to get all the
strings in that section?
It does return all the strings. The strings are NUL-terminated, with the
last string terminated by two NULs in a row. Normal string handling
routines will stop at the first NUL character: you need to write some code
to enumerate all strings.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Wow, I did not know that! Of course I have my own inifile class (I think it
was the first C++ class I ever wrote!) because GetPrivateProfileString is
EXTREMELY slow under "DOS-Windows" (ie. 9x etc). Also it's a perfect example
where a class interface is superior to function call because you can create
"section" classes based on your inifile class and throw away the "section"
specification. This is great when you don't know, or don't care what the
section name is (for instance if you use an inifile for a collection of
objects to iterate through).
Example is a function to load all objects from an inifile and invoke a
callback on each section:
virtual void OnCreateObject (const INIFILE::SECTION& sect)
{
Object* pObj = new Object;
pObj->m_strParameter = sect.Get ("SomeString");
pObj->m_iParameter = atol (sect.Get ("SomeInt"));
m_lstObjects += pObj;
and so on...
}
Very handy and very fast if you keep the data in memory (and of course keep
track of existing inifiles).
- Alan Carre