
Clearly and easily to understand, thanks a lot!





one star removed ... use of MFC





Try to keep this entry ini file and then try to read section COR , against key VALUE. it would not read the whole data
Any idea why does that happen?
[COR]
VALUE=abcdef77060,abcdef77061,abcdef77062,abcdef77063,abcdef77064,abcdef43913,abcdef77065,abcdef77184,abcdef77185,abcdef77186,abcdef77187,abcdef77188,abcdef77189,abcdef77190,abcdef77191,abcdef77192,abcdef77193,abcdef77194,abcdef77195,abcdef77196,abcdef77197,abcdef77198,abcdef77199,abcdef77200,abcdef77201,abcdef77202,abcdef77203,abcdef77204,abcdef77205,abcdef77206,abcdef77207,abcdef77208,abcdef77209,abcdef77210,abcdef77211,abcdef77212,abcdef77213,abcdef77214,abcdef77215,abcdef77216,abcdef77217,abcdef77218,abcdef77219,abcdef77220,abcdef77221,abcdef77222,abcdef77223,abcdef77224,abcdef77225,abcdef77226,abcdef77227,abcdef77228,abcdef77229,abcdef77230,abcdef77231,abcdef77232,abcdef77233,abcdef77234,abcdef77235,abcdef77236,abcdef77237,abcdef77238,abcdef77239,abcdef77240,abcdef77241,abcdef77242,abcdef77243,abcdef77244,abcdef77245,abcdef77246,abcdef77247,abcdef77248,abcdef77249,abcdef77250,abcdef77251,abcdef77252,abcdef77253,abcdef77254,abcdef77255,abcdef77256,abcdef77257,abcdef77258,abcdef77259,abcdef77260,abcdef77261,abcdef77262,abcdef77263,abcdef77266,abcdef77267,abcdef77268,abcdef77269,abcdef77270,abcdef77271,abcdef77272,abcdef77273,abcdef77274,abcdef77275,abcdef77276,abcdef77277,abcdef77278,abcdef77279,abcdef77280,abcdef77281,abcdef77282,abcdef77283,abcdef77284,abcdef77285,abcdef77286,abcdef77287,abcdef77288,abcdef77289,abcdef77290,abcdef77291,abcdef77292,abcdef77293,abcdef77294,abcdef77295,abcdef77296,abcdef77297,abcdef77298,abcdef77299,abcdef77300,abcdef77301,abcdef77302,abcdef77303,abcdef77304,abcdef77305,abcdef77306,abcdef77307,abcdef77308,abcdef77309,abcdef77310,abcdef77311,abcdef77312,abcdef77313,abcdef77314,abcdef77315,abcdef77316,abcdef77317,abcdef77318,abcdef77319,abcdef77320,abcdef77321,abcdef77322,abcdef77323,abcdef77324,abcdef77325,abcdef77326,abcdef77327,abcdef77328,abcdef77329,abcdef77330,abcdef77331,abcdef77332,abcdef77333,abcdef77334,abcdef77335,abcdef77336,abcdef77337,abcdef77338,abcdef77339,abcdef77340,abcdef77341,abcdef77342,abcdef77343,abcdef77344,abcdef77345,abcdef77346,abcdef77347,abcdef77432,abcdef77433,abcdef77434,abcdef77435,abcdef77436,abcdef77437,abcdef77438,abcdef77439,abcdef77440,abcdef77441,abcdef77442,abcdef77443,abcdef77444,abcdef77445,abcdef77446,abcdef77447,abcdef77448,abcdef77449,abcdef77450,abcdef77451,abcdef77452,abcdef77453,abcdef77454,abcdef77455,abcdef77456,abcdef77457,abcdef77458,abcdef77459,abcdef77460,abcdef77461,abcdef77462,abcdef77463,abcdef77464,abcdef77465,abcdef77466,abcdef77467,abcdef77468,abcdef77469,abcdef77470,abcdef77471,abcdef77472,abcdef77473,abcdef77474,abcdef77475,abcdef77476,abcdef77477,abcdef77478,abcdef77479,abcdef77480,abcdef77481,abcdef77482,abcdef77483,abcdef77484,abcdef77485,abcdef77486,abcdef77487,abcdef77488,abcdef77489,abcdef77490,abcdef77491,abcdef41582,abcdef41583,abcdef41584,abcdef41589,abcdef41593,abcdef41594,abcdef41620,abcdef41624,abcdef37836,abcdef37837,abcdef40252,abcdef40253,abcdef36046,abcdef36047,abcdef36048,abcdef36049,abcdef36064,abcdef36065,abcdef36087,abcdef36088,abcdef36126,abcdef36127,abcdef40561,abcdef40562,abcdef40637,abcdef40638,abcdef40645,abcdef40646,abcdef40647,abcdef40648,abcdef40659,abcdef40661,abcdef40662,abcdef40663,abcdef40676,abcdef40677,abcdef40678,abcdef40679,abcdef36546,abcdef36547,abcdef36550,abcdef36551,abcdef36552,abcdef36556,abcdef36557,abcdef36558,abcdef36560,abcdef36561,abcdef36562,abcdef36563,abcdef36564,abcdef36565,abcdef36566,abcdef36567,abcdef36568,abcdef36569,abcdef36570,abcdef36571,abcdef36573,abcdef36576,abcdef40956,abcdef40957,abcdef40959,abcdef40960,abcdef39829,abcdef39830,abcdef35000,abcdef35001,abcdef35004,abcdef35005,abcdef35428,abcdef35429,abcdef77492,abcdef77493,abcdef77494,abcdef77495,abcdef77496,abcdef77497,abcdef77498,abcdef77499,abcdef77500,abcdef77501,abcdef77502,abcdef77503,abcdef77504,abcdef77505,abcdef77506,abcdef77507,abcdef77508,abcdef77509,abcdef77510,abcdef77511,abcdef77512,abcdef77513,abcdef77514,abcdef77515,abcdef77516,abcdef77517,abcdef77518,abcdef77519,abcdef77520,abcdef77521,abcdef77522,abcdef77523,abcdef77524,abcdef77525,abcdef77526,abcdef77527,abcdef77528,abcdef77529,abcdef77530,abcdef77531
deeps1985





I updated two enumeration function to increase its speed performance and no limitation on data count.
MSDN: Help on GetPrivateProfileString Function:
Return Value: If either lpAppName or lpKeyName is NULL and the supplied destination buffer is too small to hold all the strings, the last string is truncated and followed by two null characters. In this case, the return value is equal to nSize minus two.
int CIniFile::GetSectionNames( CStringList* plistSectionNames )
{
int nSize = 1000;
long lRetValue = 0;
TCHAR* pacReturnData = NULL;
plistSectionNames>RemoveAll();
do
{
delete [] pacReturnData;
nSize *= 2;
pacReturnData = new TCHAR[nSize];
lRetValue = GetPrivateProfileSectionNames(pacReturnData, nSize, (LPCTSTR)m_strINiFileName);
}
while(lRetValue>=(nSize2));
TCHAR* pKey = pacReturnData;
while( *pKey )
{
CString strData(pKey);
if(!strData.IsEmpty())
plistSectionNames>InsertAfter(plistSectionNames>GetTailPosition(), strData);
pKey += strlen( pKey ) + 1;
}
delete [] pacReturnData;
return plistSectionNames>GetCount();
}
int CIniFile::GetSectionData( CString strSection, CStringList* plistSectionData )
{
int nSize = 1000;
long lRetValue = 0;
TCHAR* pacReturnData = NULL;
plistSectionData>RemoveAll();
do
{
delete [] pacReturnData;
nSize *= 2;
pacReturnData = new TCHAR[nSize];
lRetValue = GetPrivateProfileSection((LPCTSTR)strSection, pacReturnData, nSize, (LPCTSTR)m_strINiFileName);
}
while(lRetValue>=(nSize2));
TCHAR* pKey = pacReturnData;
while( *pKey )
{
CString strData(pKey);
if(!strData.IsEmpty())
plistSectionData>InsertAfter(plistSectionData>GetTailPosition(), strData);
pKey += strlen( pKey ) + 1;
}
delete [] pacReturnData;
return plistSectionData>GetCount();
}
modified on Saturday, November 6, 2010 10:07 AM





Hi,
Can anyone explain me how can I know keys count in ini file?
I created ini file which has only one section.
In that section, I have several keys.
I would like to know keys count in that section,
to proceed loop for other programs.
Could anyone tell me API or some codes to know keys count
of ini file.
Thanks in advance.





Use the following code:
int nKeyCount = pIniFileObj>getSectionData(strSectionName)>GetCount();





Hi,
Thanks for this great article.It Helped me a lot!!
Yog






This class is based on C++.
But your code is C#





How nice
Thanks





I want to know whether if you can give the relative path to the ini file instead of the absolute path





Use ./ for current directory





realyy good work, thanks much.
caner abalı





A very good work by my senior
Adnan Shaheen
QuaidiAzam University





Quit honestly, there are many issues related that you have overlooked while commenting, I must say that, some are as follows.
1) No overloaded copy constructors & assignment operator
2) returning of nonconstant pointer of class privates
3) passing parameters by value, rather then constant reference
4) Usage of CString, rather then std::string
5) Weak interface
Regards,
Ejaz.
 modified at 8:07 Saturday 15th October, 2005






Portability is my major concern, thats why I dumped the idea of using .ini files quite sometime back and use boost::serialization
Regards





Hye!!
I would like to know how I can remove a key?
Thanks.





long CIniReader::delKey(CString strValue, CString strKey, CString strSection)
{
m_lRetValue = WritePrivateProfileString (strSection, strKey,
NULL, m_strFileName);
return m_lRetValue;
}





Good, This helped me a lot.
Regards,
Rajendran





Hi,
when i'm using CIniReader Class outside the TestIni Project,
with VC++6.0 i get the following error:
(sorry, i'm just a beginner)
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/Test.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Can anyone help me? Thanx.





This is probably because of your inappropriate project settings:
Following is what i am pasting from MSDN.

When compiling an MFC application using the singlethreaded runtime library, you receive the following two unresolved external error messages:
nafxcwd.lib(thrdcore.obj) : error LNK2001:
unresolved external symbol "__beginthreadex"
nafxcwd.lib(thrdcore.obj) : error LNK2001:
unresolved external symbol "__endthreadex"

Solution:
Select the PROJECT menu
Select the SETTINGS... option.
Select the tab, C/C++.
Select CODE GENERATION on the Category list box.
Finally, make a selection other than SINGLETHREADED on the Use Run Time Library list box.

for details refer to MSDN.
@!$h@





Just to tell you, this class is not based on MFC, instead it uses SDK functions. So you can use my class anywhere, in your C++, Win32 or MFC code. Enjoy!!;)
@!$h@
My free code and articles website http://aishai.netfirms.com





looking at the header file, I found #include <afxcoll.h> and functions returning CString. I doubt I can really use it in any nonMFC project.





I had a ini file that had around 20 sections, each of which had around 5000 key pair values. Used this class, seems like it was taking forever to read/write through these set of classes.
Could you please improve its performance, or atleast advise me how can i do this?
Thanks a lot




