This is a function that should be in PocketPC / CE but is not because ini files are considered old news. However, when you're porting C++ applications, you run into this a lot.
Disclaimer: This does not in any means handle all the features of
GetPrivateProfileString, nor is it bug free or very well tested. It may destroy the universe etc. etc. All it does currently is read basic ini settings which is all I need it for. I also have wrappers on top of this which handle a lot of functionality which probably should be present here.
GetPrivateProfileString for more details.
I am hoping that others will add to this, one day making it the Win32 equivalent. Here is the code:
static DWORD GetPrivateProfileString(LPCTSTR lpSection, LPCTSTR lpKey,
LPTSTR lpDefault, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR szPathAndFile)
fstream clFileOp(szPathAndFile,ios::in); string clline; CStringA clkey( lpKey);
if (clFileOp.is_open() == FALSE )
getline ( clFileOp, clline );
if ( clline.find( clkey ) != -1 )
int nEquals = clline.find( "=" );
if ( nEquals == -1 )
string clres = clline.substr( nEquals +1, clline.length() - nEquals );
CString clret ( clres.c_str() );
_tcscpy ( lpBuffer,clret );