C++ String Wrapper Classes
First should understand that Windows APIs are defined and documented in terms of TCHAR,which can be MBCS or Unicode characters depending on whether you define the _MBCS or _UNICODE symbol when compiling.
Type: Meaning:
WCHAR Unicode character(wchar_t)
TCHAR MBCS or Unicode character, depending on preprocessor settings
LPSTR string of char(char *)
LPCSTR constant string of char(const char *)
LPWSTR string of WCHAR(WCHAR *)
LPCWSTR constant string of WCHAR(const WCHAR *)
LPTSTR string of TCHAR(TCHAR *)
LPCTSTR constant string of TCHAR(const TCHAR *)
OLECHAR Unicode character(wchar_t)
LPOLESTR string of OLECHAR(OLECHAR *)
LPCOLESTR constant string of OLECHAR(const OLECHAR *)
_T(x) Prepends L to the literal in Unicode builds
Also there are also some variants on _T that you might encouter in documentation or sample code, there are TEXT,_TEXT,__TEXT,and __T,that all do the same things
MFC Classes:
An MFC CString holds TCHARs,so the exact character type depends on the preprocessor symbols you have defined. In general, CString is like a STL string .
Following some examples:
CString s1=”char string”;//construct from a LPCSTR
CString s2=_T(”wide char string”);//construct from a LPCWSTR
NOTE: The only legal cast you can apply to a CString is a cast to LPCTSTR, you should know that cast to LPTSTR is wrong.If you want to cast to LPTCHAR, please use CString.GetBuffer(0),but you should invoke the CString.ReleaseBuffer after you use that.
Type: Meaning:
WCHAR Unicode character(wchar_t)
TCHAR MBCS or Unicode character, depending on preprocessor settings
LPSTR string of char(char *)
LPCSTR constant string of char(const char *)
LPWSTR string of WCHAR(WCHAR *)
LPCWSTR constant string of WCHAR(const WCHAR *)
LPTSTR string of TCHAR(TCHAR *)
LPCTSTR constant string of TCHAR(const TCHAR *)
OLECHAR Unicode character(wchar_t)
LPOLESTR string of OLECHAR(OLECHAR *)
LPCOLESTR constant string of OLECHAR(const OLECHAR *)
_T(x) Prepends L to the literal in Unicode builds
Also there are also some variants on _T that you might encouter in documentation or sample code, there are TEXT,_TEXT,__TEXT,and __T,that all do the same things
MFC Classes:
An MFC CString holds TCHARs,so the exact character type depends on the preprocessor symbols you have defined. In general, CString is like a STL string .
Following some examples:
CString s1=”char string”;//construct from a LPCSTR
CString s2=_T(”wide char string”);//construct from a LPCWSTR
NOTE: The only legal cast you can apply to a CString is a cast to LPCTSTR, you should know that cast to LPTSTR is wrong.If you want to cast to LPTCHAR, please use CString.GetBuffer(0),but you should invoke the CString.ReleaseBuffer after you use that.
浙公网安备 33010602011771号