1. 程式人生 > >win32應用程式,TCHAR與CHAR的相互轉換

win32應用程式,TCHAR與CHAR的相互轉換

TCHR 與 CHAR相互轉換

含義

TCHAR:在Unicode編碼下,為寬字元wchar;在Ansi編碼下,為字元char。
CHAR:是在Ansi編碼下字串格式。

TChar to Char

呼叫函式:
int SHTCharToAnsi(
LPCTSTR pwszSrc,
LPSTR pszDst,
int cchBuf
);
引數:
pwszSrc
[in] A pointer to a null-terminated TCHAR string to be converted to ANSI.
pszDst
[out] A pointer to a buffer that will receive the converted characters. The buffer must be large enough to contain the number of CHAR characters specified by the cchBuf parameter, including room for a terminating null character.
cchBuf
[in] The number of CHAR values that can be contained by the buffer pointed to by pszDst. The value assigned to parameter must be greater than zero.

CHAR To TCHAR

呼叫函式:
int SHAnsiToT(
LPCSTR pszSrc,
LPTSTR pwszDst,
int cwchBuf
);

引數:
pszSrc
[in] A pointer to a null-terminated ANSI string to be converted to TCHAR.
pwszDst
[out] A pointer to a buffer that will receive the string specified by pszSrc, after the ANSI characters have been converted to TCHAR. The buffer must be large enough to contain the number of TCHAR characters specified by the cwchBuf parameter, including a terminating null character.
cwchBuf
[in] The number of TCHR characters that can be contained by the buffer pointed to by pwszDst. This parameter must be greater than zero.