DWORD GetPrivateProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName) { FILE *f = NULL; DWORD dwRet = 0; ASSERT(lpReturnedString != NULL); ASSERT(lpFileName != NULL); ZeroMemory(lpReturnedString, nSize); int err = 0; const TCHAR *index = _tcschr(lpFileName, '//'); if (index == NULL) { TCHAR buf[MAX_PATH] = _T("//Windows//"); _tcscat_s(buf, MAX_PATH, lpFileName); err = _tfopen_s(&f, lpFileName, _T("r+")); } else err = _tfopen_s(&f, lpFileName, _T("r+")); if (err != 0) dwRet = 0; char c; DWORD i = 0, j = 0; if (lpAppName == NULL) { while (fread(&c, sizeof(char), 1, f)) { if ( c == '[') { while (i<nSize && fread(&lpReturnedString[i], sizeof(char), 1, f)) { if (lpReturnedString[i++] == ']') { lpReturnedString[i-1] = '/0'; break; } } } } if (i < nSize) { lpReturnedString[i] = '/0'; dwRet = i; }