64,637
社区成员
发帖
与我相关
我的任务
分享
typedef struct tag_GameInfo
{
string m_strGameName;
void clear()
{
ZeroMemory(this, sizeof(tag_GameInfo));
}
tag_GameInfo()
{
ZeroMemory(this, sizeof(tag_GameInfo));
}
~tag_GameInfo()
{
ZeroMemory(this, sizeof(tag_GameInfo));
}
}GAMEINFO, *LPGAMEINFO;
string GetString( char * strIniPath, const char * strFront, const char * strBack )
{
string strString = "";
string strCurPath = GetCurPath();
char strTm[MAX_PATH] = {0};
sprintf_s(strTm, "%s\\%s", strCurPath.c_str(), strIniPath);
strIniPath = strTm;
CString strTemp = "";
GetPrivateProfileString( strFront, strBack, "", strTemp.GetBuffer(MAX_PATH), MAX_PATH, strIniPath);
return strString = strTemp.GetBuffer(0);
}
void CGameTreeView::GetAllGameInfo()
{
int iGameCount = GetInt("attrres\\GameInfo.ini", "info", "count");
for ( int i = 0; i < iGameCount; i++ )
{
char strTm[MAX_PATH] = {0};
sprintf_s(strTm, "game%d", i);
LPGAMEINFO pGameInfo = new GAMEINFO;
//string strGameName = GetString("attrres\\GameInfo.ini", strTm, "name"); //不会内存泄露
pGameInfo->m_strGameName = GetString("attrres\\GameInfo.ini", strTm, "name"); //造成16 bytes long的内存泄露!!!
m_mapGameInfo[pGameInfo->m_uiGameID] = pGameInfo;
}
}
CGameTreeView::~CGameTreeView()
{
map<UINT, LPGAMEINFO>:: iterator iter_GameInfo = m_mapGameInfo.begin();
for (; iter_GameInfo != m_mapGameInfo.end(); iter_GameInfo++)
{
if ( NULL != iter_GameInfo->second )
{
delete iter_GameInfo->second;
iter_GameInfo->second = NULL;
}
}
m_mapGameInfo.clear();
}
string GetString( char * strIniPath, const char * strFront, const char * strBack )
{
string strString = "";
string strCurPath = GetCurPath();
char strTm[MAX_PATH] = {0};
sprintf_s(strTm, "%s\\%s", strCurPath.c_str(), strIniPath);
strIniPath = strTm;
CString strTemp = "";
GetPrivateProfileString( strFront, strBack, "", strTemp.GetBuffer(MAX_PATH), MAX_PATH, strIniPath);
strString = strTemp;
strTemp.ReleaseBuffer();
return strString;
}