-
What is this code doing?
Code:
bool Trade::ReadConfiguration()
{
bool bGotConfigValues = true;
char sIniPath[255];
GetCurrentDirectory( sizeof(sIniPath), sIniPath );
sprintf( sIniPath,"%s\\..\\..\\%s.ini",sIniPath, INI_FILE_BASE);
GetPrivateProfileString( _T(INI_FILE_SECTION), _T("UserName"), _T(""), m_szUserName, sizeof(m_szUserName), sIniPath );
GetPrivateProfileString( _T(INI_FILE_SECTION), _T("Password"), _T(""), m_szPassword, sizeof(m_szPassword), sIniPath );
GetPrivateProfileString( _T(INI_FILE_SECTION), _T("Part"), _T(""), m_szPart, sizeof(m_szPart), sIniPath );
GetPrivateProfileString( _T(INI_FILE_SECTION), _T("Server"), _T(""), m_szConnection, sizeof(m_szConnection), sIniPath );
-
it reads an ini file. but its not correctly coded ;)
-
Not coded correctly... it's from an api template?
-
Code:
bool bGotConfigValues = true;
char sIniPath[255];
GetCurrentDirectory( sizeof(sIniPath), sIniPath );
sprintf( sIniPath,"%s\\..\\..\\%s.ini",sIniPath, INI_FILE_BASE);
GetCurrentDirectory might not return the real directory path, its not constant. try to use GetModuleFileName(NULL, sIniPath); instead. it retrieves the whole path of the exe including filename, but you can strip the filename off
-
So it's reading from UserConfig.ini file 3 directories up.
In my project implementation I’m including the ini file with all the source code so 1 directory up from the build. Would something like this work:
Code:
sprintf( sIniPath,"%s..\\%s.ini",sIniPath, INI_FILE_BASE);
I’ll work on making things better after I just get this to work.