// Used to retrieve a value give the section and key
CString CIniReader::getKeyValue(CString strKey,CString strSection)
{
char ac_Result[255];
// Get the info from the .ini file
m_lRetValue = GetPrivateProfileString((LPCTSTR)strSection,(LPCTSTR)strKey,
"",ac_Result, 255, (LPCTSTR)m_strFileName);
CString strResult(ac_Result);
return strResult;
}
// Used to add or set a key value pair to a section
long CIniReader::setKey(CString strValue, CString strKey, CString strSection)
{
m_lRetValue = WritePrivateProfileString (strSection, strKey,
strValue, m_strFileName);
return m_lRetValue;
}
// Used to find out if a given section exists
BOOL CIniReader::sectionExists(CString strSection)
{
char ac_Result[100];
CString csAux;
// Get the info from the .ini file
m_lRetValue = GetPrivateProfileString((LPCTSTR)strSection,NULL,
"",ac_Result, 90, (LPCTSTR)m_strFileName);
// Return if we could retrieve any info from that section
return (m_lRetValue > 0);
}
// Used to retrieve all of the section names in the ini file
CStringList* CIniReader::getSectionNames() //returns collection of section names
{
char ac_Result[2000];
m_sectionList->RemoveAll();
// Used to retrieve all key/value pairs of a given section.
CStringList* CIniReader::getSectionData(CString strSection)
{
char ac_Result[2000]; //change size depending on needs
m_sectionDataList->RemoveAll();
m_lRetValue = GetPrivateProfileSection((LPCTSTR)strSection, ac_Result, 2000, (LPCTSTR)m_strFileName);