CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    117

    "abnormal program termination"?!

    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.


  2. #2
    Join Date
    May 1999
    Posts
    18

    Re: "abnormal program termination"?!

    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


  3. #3
    Join Date
    Apr 1999
    Posts
    117

    Re: "abnormal program termination"?!

    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.


  4. #4
    Join Date
    Apr 1999
    Posts
    396

    Re: "abnormal program termination"?!

    You can enumerate sections and keys with it too


  5. #5
    Join Date
    Apr 1999
    Posts
    117

    Re: "abnormal program termination"?!

    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?


  6. #6
    Join Date
    Apr 1999
    Location
    Monterrey, Mexico
    Posts
    21

    Re: "abnormal program termination"?!

    please take a look at functions like :

    GetPrivateProfileSectionNames

    http://msdn.microsoft.com/library/sd...egapi_3k1f.htm

    you should be using the registry anyway...



    adiós!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured