I am modifying an existing C ++ application and moving some values ββthat are currently hardcoded.
I do this with one class that will "manage" all of this and hold map<CString, CString> values ββfrom the INI file.
Currently, I have to read each value separately using the ::GetPrivateProfileString function - can I somehow read the whole section instead of a single value?
Prefer not to read the file manually, but if there is a reasonable (i.e. efficient + easy to use) existing method, I am open to suggestions.
Edit: now he had to use it βfor real,β and the solution did pass NULL as the value of lpKeyName. Full code including return value analysis:
char buffer[MAX_STRING_SIZE]; int charsCount = ::GetPrivateProfileString("MySection", NULL, NULL, buffer, MAX_STRING_SIZE, m_strIniPath); CString curValue; curValue.Empty(); char curChar = '\0'; for (int i = 0; i < charsCount; i++) { curChar = buffer[i]; if (curChar == '\0') { if (curValue.GetLength() > 0) HandleValue(curValue); curValue.Empty(); } else { curValue.AppendFormat("%c", curChar); } } if (curValue.GetLength() > 0) HandleValue(curValue);
This is not trivial since it returns keys separated by a null character (EOS?), So I had to extract them using a loop like the above - share it here for all who might need it. :-)
source share