Start by exploring the different types of strings. For example, char*, LPSTRand LPCSTRare connected with each other and retain ANSI symbols; the latter is a pointer to a constant string. Similarly wchar_t*, WCHAR*, LPWSTRand LPCWSTRare connected and stored Unicode characters; again, the last is a pointer to a constant string.
Then look what you mean when you say something like “returns char *”, since most Windows APIs do nothing. Instead, they take LPSTR(a pointer to a char buffer) or LPWSTR(a pointer to a WCHAR buffer) and write to the buffer. These APIs again almost always take the number of characters available in the buffer, or have document buffer size requirements such as MAX_PATH.
. ++ 11 , a std::wstring std::string , . , API, GetEnvironmentVariable, . , , , :
std::wstring GetEnvironmentVariable(const std::wstring& strName)
{
DWORD cchValue = MAX_PATH;
std::wstring strValue;
strValue.resize(cchValue);
cchValue = GetEnvironmentVariable(strName.c_str(), &strValue[0], cchValue);
if (cchValue > MAX_PATH)
{
strValue.resize(cchValue);
cchValue = GetEnvironmentVariable(strName.c_str(), &strValue[0], cchValue);
}
if (0 == cchValue)
{
}
strValue.resize(cchValue);
return strValue;
}
, .
- Windows 9x,
LPTSTR , typedef tstring, std::wstring std::string UNICODE ( ' d , ). A W, ++, Windows. - , - , , .
- API-, in-out .
- API-, GetWindowText, /, , . . answer . ( , ).
-, . , - Windows, , , . , , ; , , , iostream. , .