Char * ReadString (char * szSection, char * szKey, const char * szDefaultValue)
{
Char * szResult=new char [MAXSTRINGLEN];
STD: : from & lt; Char> PResult (szResult);//add smart Pointers
Memset (szResult, 0 x00 MAXSTRINGLEN);
GetPrivateProfileString (LPCTSTR szSection, LPCTSTR szKey,
(LPCTSTR) szDefaultValue, szResult MAXSTRINGLEN, LPCTSTR m_szFileName);
Return szResult;
}
CodePudding user response:
TCHAR * ReadString (TCHAR * szSection, TCHAR * szKey, const TCHAR * szDefaultValue)
{
The static TCHAR szResult [MAXSTRINGLEN];
Memset (szResult, 0 x00, MAXSTRINGLEN * sizeof (TCHAR));
GetPrivateProfileString (LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szDefaultValue, szResult, MAXSTRINGLEN, LPCTSTR m_szFileName);
Return szResult;
}
CodePudding user response:
Don't return is empty? That you still have what meaning this functionCodePudding user response:
Static is automatically released?CodePudding user response:
Must not, szResult is your return value, return after you release the pointer, the return value and purpose?I think you should put your smart Pointers snippet to call this function
CodePudding user response:
I'm wrong and you are using a static array, thanks zhao four teachersCodePudding user response:
Thank you, friends whoCodePudding user response:
Ask zhao four teachers, checked the, static array is automatically released after the function, isn't it? So, the return value is no problem?CodePudding user response:
Life cycle is long, static char [],Such use, single thread no problem, multithreading,,, out of the question,
CodePudding user response:
Smart Pointers can not exceed the scope to use, it is recommended that the passed in parameter way, who apply for destruction ofLPCTSTR ReadString (LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szDefaultValue, LPTSTR szResult, int iBuffSize)
{
GetPrivateProfileString (szSection szKey, szDefaultValue szResult, iBuffSize, m_szFileName);
Return szResult;
}
CodePudding user response: