Click to See Complete Forum and Search --> : "abnormal program termination"?!


Quakey
June 7th, 1999, 02:28 PM
Hi there,
I'm trying to write a class that reads and writes INI files. One of my class's member function is
CINIKey::EnumSection(string& szBuffer, const int index) which just returns a string containing the
section name of a specific index in an INI file. The code I have is the following.

bool CINIKey::EnumSection(string& szBuffer,const int index)
{
for(int i=0;i<=index;i++)
{
szBuffer=ExtractSection();
nStartPos+=szBuffer.length();//Advance the position so it reads the next available section
}
if(szBuffer.size()==0) //No more section is left to extract
return false;
else
return true; //Still more sections left to be extracted

}




The call to ExtractSection() just extracts and returns a the string containing the section name specified by
nStartPos which is initially 0 so it searches for the first [section name] in the file. If I increase nStartPos
to after the first section's end bracket, then it will find the next section by finding another '['. Anyway,
I try to use the EnumSection like the following...


CINIKey key;
bool bResult;
int i;
for(i=0,bResult=true;bResult==true;i++)
{
bResult=key.EnumSection(value,i);
cout << value << endl;
}




That code is supposed to list all the section name in the INI file one by one and it actually works. The
problem is I also get the error message "abnormal program termination" at the end. It's also apprent that
the program terminates BEFORE my main returns anything! Please tell me what's wrong. Thanks.

Luc B.
June 7th, 1999, 03:11 PM
Why would you want to write a class to read/write to ini files when you can use GetProfileString/WriteProfileString !?!?!?!?

Only a comment...

Have a nice day :)

Quakey
June 7th, 1999, 07:55 PM
Hi there,
I know API supports it but it's not enought for me. For example, I'd like to enumerate the sections or
entries.

Todd Jeffreys
June 7th, 1999, 08:06 PM
You can enumerate sections and keys with it too :)

Quakey
June 8th, 1999, 11:55 AM
Hi there,
Can they? From the doc in MSDN, both Write/ReadProfileString() require the section and entry
name for the parameters. What if we DO NOT know the names?

eperales
June 8th, 1999, 01:24 PM
please take a look at functions like :

GetPrivateProfileSectionNames

http://msdn.microsoft.com/library/sdkdoc/winbase/regapi_3k1f.htm

you should be using the registry anyway...



adiós!