반응형
http://whoim.tistory.com/entry/INI-섹션정보-얻기-GetPrivateProfileSectionNames
처음에는 이분 블로그에서 해당 소스를 보고 사용하였었다..
며칠후에 해당 소스를 보다가.. 문자열이 \0 로 구분되는것에 착안
좀 더 최적화를 해보았다.
기존 코드
char szBuf[1024] = {0x00,};
char szSect[512] = {0x00,};
DWORD nCnt = ::GetPrivateProfileSectionNames(szBuf, 1024, strPath);
int nPos = 0;
BOOL bMakedSect = FALSE; // 하나의 섹션을 구성완료하면 TRUE하여 pos를 0으로 초기화
for(int i=0; i < (int)nCnt; i++, nPos++)
{
if(szBuf[i] != '\0'){
if(bMakedSect) nPos = 0;
memcpy(szSect + nPos, szBuf+i, 1);
bMakedSect = FALSE;
continue;
}
else{
szSect[i] = '\0';
nTemp = m_cbApplication.AddString(szSect);
if( strcmp(m_strSection, szSect) == 0)
{
nIdx = nTemp;
}
memset(szSect, 0x00, sizeof(szSect));
bMakedSect = TRUE;
}
nTemp = m_cbApplication.AddString(szSect);
if( strcmp(m_strSection, szSect) == 0)
{
nIdx = nTemp;
}
}
나름대로 최적화 코드
char szBuf[1024] = {0x00,};
char szSect[512] = {0x00,};
DWORD nCnt = ::GetPrivateProfileSectionNames(szBuf, 1024, strPath);
int nPos = 0;
// 2010.08.13 Section 정보 최적화
for(int i=0; i < (int)nCnt; nPos++)
{
strcpy(szSect , szBuf + i);
i += strlen(szSect) + 1;
nTemp = m_cbApplication.AddString(szSect);
if( strcmp(m_strSection, szSect) == 0)
{
nIdx = nTemp;
}
}
'Programming > MFC' 카테고리의 다른 글
| 무료 라인 차트 (0) | 2014.05.27 |
|---|---|
| MFC 문자가 한글인지 검사/체크하는 방법들 (0) | 2013.01.30 |
| UNICODE <-> ANSI 변환 (0) | 2011.11.24 |
| 컨트롤을 상속 클래스, NM_CLICK 가 부모윈도우에 통지가 안될때.. (2) | 2010.12.03 |
| CListCtrl 파일로 저장 - CListCtrl Save, Load (0) | 2010.08.12 |
| CImageList Class (0) | 2008.10.08 |
| MFC 에서 서로 다른 클래스의 핸들 얻어오기 (1) | 2008.05.30 |
| Visual Studio 6.0 + Windows XP 설치 해결법 (0) | 2008.05.28 |