Source:TyranoMapHack123/IniReader.cpp

From Codemotion
Jump to: navigation, search

Source:TyranoMapHack123/IniReader.cpp

Description

Ini Reading class by Xiangxiong Jian: http://www.codeproject.com/KB/cpp/IniReader.aspx.

Code

Parent Directory: Source:TyranoMapHack123
Plain Code: edit

  1. #include "IniReader.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4.  
  5. CIniReader::CIniReader(char* szFileName)
  6. {
  7.  memset(m_szFileName, 0x00, 255);
  8.  memcpy(m_szFileName, szFileName, strlen(szFileName));
  9. }
  10. int CIniReader::ReadInteger(char* szSection, char* szKey, int iDefaultValue)
  11. {
  12.  int iResult = GetPrivateProfileInt(szSection,  szKey, iDefaultValue, m_szFileName); 
  13.  return iResult;
  14. }
  15. float CIniReader::ReadFloat(char* szSection, char* szKey, float fltDefaultValue)
  16. {
  17.  char szResult[255];
  18.  char szDefault[255];
  19.  float fltResult;
  20.  sprintf(szDefault, "%f",fltDefaultValue);
  21.  GetPrivateProfileString(szSection,  szKey, szDefault, szResult, 255, m_szFileName); 
  22.  fltResult =  atof(szResult);
  23.  return fltResult;
  24. }
  25. bool CIniReader::ReadBoolean(char* szSection, char* szKey, bool bolDefaultValue)
  26. {
  27.  char szResult[255];
  28.  char szDefault[255];
  29.  bool bolResult;
  30.  sprintf(szDefault, "%s", bolDefaultValue? "True" : "False");
  31.  GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName); 
  32.  bolResult =  (strcmp(szResult, "True") == 0 || strcmp(szResult, "true") == 0) ? true : false;
  33.  return bolResult;
  34. }
  35. char* CIniReader::ReadString(char* szSection, char* szKey, const char* szDefaultValue)
  36. {
  37.  char* szResult = new char[255];
  38.  memset(szResult, 0x00, 255);
  39.  GetPrivateProfileString(szSection,  szKey, szDefaultValue, szResult, 255, m_szFileName); 
  40.  return szResult;
  41. }
Personal tools