WideCharToMultiChar()/MultiCharToWideChar()编码转换疑问?

teleinfor 2010-08-26 09:56:44



这两个函数如何工作的?疑问列表:

WideCharToMultiChar()
1、这个函数吧UNICODE转换为ANSI字符串,对么?
2、它对于UNICODDE的UTF-8/UTF-16是如何工作的?

MultiCharToWideChar()
1、这个函数是实现的ANSI char到UNICODE的转换,那么结果是哪一种UNICODE编码(UTF-8/UTF-16)?

一直没弄清楚这块的知识。
...全文
249 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2010-08-26
  • 打赏
  • 举报
回复
WideCharToMultiChar 有参数指定字符集的编码格式等...
teleinfor 2010-08-26
  • 打赏
  • 举报
回复
尤其在xml文档的声明部分又可以指定tagging标明使用的encoding = utf-8/utf-16/gb2312等编码。可是保存的时候又可以存储为UTF-8/UTF-16/ANSI等。

我都被搞晕了,请明白的大侠给讲讲,谢谢。
teleinfor 2010-08-26
  • 打赏
  • 举报
回复
MultiByteToWideChar()
---------------------
Maps a character string to a wide character (Unicode UTF-16) string. The character string mapped by this function is not necessarily from a multibyte character set.

Note: The ANSI code pages can be different on different computers, or can be changed for a single computer, leading to data corruption. For the most consistent results, applications should use Unicode, such as UTF-8 (code page 65001) or UTF-16, instead of a specific code page, unless legacy standards or data formats prevent the use of Unicode. If use of Unicode is not possible, applications should tag the data stream with the appropriate encoding name when protocols allow it. HTML, XML, and HTTP files allow tagging, but text files do not.

这个函数倒是明确说了是把一个ANSI转换为UTF-16编码。

反向转换函数就没有细说了。
WideCharToMultiByte()
---------------------
Maps a wide character string to a new character string. The new character string is not necessarily from a multibyte character set.

Note: The ANSI code pages can be different on different computers, or can be changed for a single computer, leading to data corruption. For the most consistent results, applications should use Unicode, such as UTF-8 (code page 65001) or UTF-16, instead of a specific code page, unless legacy standards or data formats prevent the use of Unicode. If use of Unicode is not possible, applications should tag the data stream with the appropriate encoding name when protocols allow it. HTML, XML, and HTTP files allow tagging, but text files do not.
wltg2001 2010-08-26
  • 打赏
  • 举报
回复
Windows平台下默认的Unicode编码是UTF-16,所以上面的两个函数都是基于UFT-16的。

16,472

社区成员

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

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

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