win32应用程序,TCHAR与CHAR的相互转换

本文详细介绍了TCHAR与CHAR在不同编码环境下如何进行相互转换。TCHAR在Unicode下为wchar,在Ansi下为char;CHAR则为Ansi编码下的字符串格式。文章提供了TChartoChar与CHARToTCHAR的具体函数调用方式及参数说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值