Share the read/write source code of the Self-written test INI File

Source: Internet
Author: User

Bool ctest1_dlg: readini () // read ini
{
Char filepath [max_path];
Char databuf [1024];
: Getcurrentdirectory (max_path, filepath );
Strcat (filepath ,"\\");
Strcat (filepath, "config. ini ");
Int COUNT = calccount (); // counts the number of existing segments in the INI file. For details, see the following.
Cstring secname = "section ";
Cstring temp;
Temp. Format ("% d", Count-1 );
Secname + = temp;

: Getprivateprofilestring (secname, "User ID", "", databuf, 1024, filepath );
M_username = databuf;
: Getprivateprofilestring (secname, "password", "", databuf, 1024, filepath );
M_passwd = databuf;
Return false;

}

Bool ctest1_dlg: writeini () // write ini
{

Char filepath [max_path];
: Getcurrentdirectory (max_path, filepath );
Strcat (filepath ,"\\");
Strcat (filepath, "config. ini ");
Int COUNT = calccount (); // same as above
Cstring secname = "section ";
Cstring temp;
Temp. Format ("% d", count );
Secname + = temp;
: Writeprivateprofilestring (secname, "User ID", m_username, filepath );
: Writeprivateprofilestring (secname, "password", m_passwd, filepath );

Return true;
}

Int ctest1_dlg: calccount ()
{
Char chsectionnames [1024] = {0 };
Char * psectionname; // Save the first address of a specified node name string
Int I; // point to a location of the array chsectionnames, starting from 0, with sequential descendant
Int J = 0; // used to save the first address of the string of the next node name
Int COUNT = 0; // count the number of nodes.
: Getprivateprofilesectionnames (chsectionnames, 1024, ". \ config. ini ");
For (I = 0; I <1024; I ++, J ++)
{
If ('\ 0' = chsectionnames [0])
Break;
If ('\ 0' = chsectionnames [I])
{
Psectionname = & chsectionnames [I-j];
J =-1;
// Afxmessagebox (psectionname );
Count ++;
If ('\ 0' = chsectionnames [I + 1])
{
Break;
}
}
}
Return count;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.