What is this code doing?

This is a discussion on What is this code doing? within the C++ Programming forums, part of the General Programming Boards category; 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"), ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    31

    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 );

  2. #2
    @codeguru
    Join Date
    Jan 2006
    Posts
    34
    it reads an ini file. but its not correctly coded

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    31
    Not coded correctly... it's from an api template?

  4. #4
    @codeguru
    Join Date
    Jan 2006
    Posts
    34
    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

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    31
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21