Finally I have decided to write my own function which will read the integer value from INI and does the validation according to the input as shown below.
long ReadIntegerValueFromIni( const CString& csAppName_i,
const CString& csKeyName_i,
const CString& csDefaultVal_i,
const CString& csFileName_i,
const int nMinVal_i,
const int nMaxVal_i )
{
long lKeyValue = 0;
int nDefaultVal = _ttoi( csDefaultVal_i );
try
{
const int SUCCESS_RET = 1;
TCHAR tcszBuf[ MAX_PATH ];
TCHAR tcszBufTemp[ MAX_PATH ];
lKeyValue = nDefaultVal;
GetPrivateProfileString( csAppName_i, csKeyName_i, csDefaultVal_i, tcszBuf, sizeof( tcszBuf ),
csFileName_i );
if( SUCCESS_RET != swscanf( tcszBuf, _T( "%d%s" ), &lKeyValue, &tcszBufTemp ))
{
lKeyValue = nDefaultVal;
}
else if( nMinVal_i > lKeyValue || nMaxVal_i < lKeyValue )
{
lKeyValue = nDefaultVal;
}
else
{
}
}
catch( ... )
{
lKeyValue = nDefaultVal;
}
return lKeyValue;
}
Valid comments are welcome.