wcstombs()的返回值

yinleish 2006-10-11 09:13:11
CXXXXX::setXMLData(BSTR data)
{
int bytelen = wcstombs(NULL, data, SysStringByteLen(data)+1);
........
}
有上述结构的函数,其中data中是含有双字节字符(中文)的字符串。
现在在英文操作系统下,
1。区域语言为中文的时候
bytelen的值为-1
2。区域语言为英文的时候
bytelen的值为the number of bytes written into the multibyte output string(正常的值)
请问这是什么原因?wcstombs这个函数和系统以及设置有什么特定的联系吗?
...全文
890 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixiaosan 2006-10-17
  • 打赏
  • 举报
回复
http://blog.csdn.net/lixiaosan/archive/2006/09/06/1183925.aspx
cloudgamer 2006-10-12
  • 打赏
  • 举报
回复
帮顶
Chrissie 2006-10-11
  • 打赏
  • 举报
回复

能请楼上介绍一下Unicode编译吗?
wlwlxj 2006-10-11
  • 打赏
  • 举报
回复
建议采用Unicode编译
DentistryDoctor 2006-10-11
  • 打赏
  • 举报
回复
Return Value
If wcstombs successfully converts the multibyte string, it returns the number of bytes written into the multibyte output string, excluding the terminating NULL (if any). If the mbstr argument is NULL, wcstombs returns the required size in bytes of the destination string. If wcstombs encounters a wide character it cannot convert to a multibyte character, it returns –1 cast to type size_t and sets errno to EILSEQ.

Remarks
The wcstombs function converts the wide-character string pointed to by wcstr to the corresponding multibyte characters and stores the results in the mbstr array. The count parameter indicates the maximum number of bytes that can be stored in the multibyte output string (that is, the size of mbstr). In general, it is not known how many bytes will be required when converting a wide-character string. Some wide characters will require only one byte in the output string; others require two. If there are two bytes in the multibyte output string for every wide character in the input string (including the wide character NULL), the result is guaranteed to fit.

If wcstombs encounters the wide-character null character (L'\0') either before or when count occurs, it converts it to an 8-bit 0 and stops. Thus, the multibyte character string at mbstr is null-terminated only if wcstombs encounters a wide-character null character during conversion. If the sequences pointed to by wcstr and mbstr overlap, the behavior of wcstombs is undefined.

If the mbstr argument is NULL, wcstombs returns the required size in bytes of the destination string.

wcstombs validates its parameters. If wcstr is NULL, or if count is greater than INT_MAX, this function invokes the invalid parameter handler, as described in Parameter Validation . If execution is allowed to continue, the function sets errno to EINVAL and returns -1.

wcstombs uses the current locale for any locale-dependent behavior; _wcstombs_l is identical except that it uses the locale passed in instead.

In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. For more information, see Secure Template Overloads.
baojian88888 2006-10-11
  • 打赏
  • 举报
回复
应该和本地代码页CodePage有关,看看setlocale函数

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧