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.

猜你喜欢

转载自blog.csdn.net/weixin_30536299/article/details/84293421