作者purpose (purpose)
看板Programming
标题Re: [问题] oem string 是什麽?
时间Tue Sep 18 17:21:19 2012
※ 引述《jonce007 (汪汪)》之铭言:
: 最近在看mail list的讨论,其中有一段提到:
: Hi,
: Never use *ANSITOOEM* or any other similar functions.
: All what is necessary is correct CP set in HVM by
: hb_cdpSelect( <cCP> ) or SET( _SET_CODEPAGE, <cCP> )
: (both functions make the same operation)
: best regards,
: P******
: 虽然我知道big5中的codepage是cp950,
: 从来用过 ANSIToOEM() or OEMTOANI()的函数
: 一直不明白什麽是ansi string 什麽又是oem string,
: 又google不到中文说明
: 小弟是自学程式的。请前辈先进不吝说明一下^^
随便一个文字档,在硬体内部都是用二进位记录其内容,也就是 010101...
然後有个叫编码的东西,首先把这些二进位编排成「1位元-1位元-1位元...」格式
也就是像「0x41-0x42-0x43」这样的十六进位形式,接着再规定
0x41 代表英文字母 'A'
0x42 代表英文字母 'B'
0x43 代表英文字母 'C'
然後有些国家的文字比较麻烦,像中、日、韩,文字的数量比较多,所以只要碰到该组
内码值 >= 0x80 就代表这是连续内码,要跟下个内码值结合
0xA4CF-0xABFC-0xBCD0 就是繁体中文编码 CP950 下的「反指标」三个字
所谓的 ANSI 编码就是这种东西。
当你的作业系统安装的时候,使用语言选择繁体中文,则电脑的 Active CodePage 值
就是设定为 CP950,所以文件内容中的 0xA4CF 内码就被解读成 '反' 字。
当你的作业系统使用日文时,则同样一份文件,同样的内码值 0xA4CF 就不再被解读
成 '反' 这个字,而会是日文的标点符号。
那麽作业系统使用英文时,那麽你的 Active CodePage 就会是 CP-1252。
古早在 DOS 时代的作业系统,也可以选择使用什麽语言,在当时的英文 DOS 下,
其 CodePage 才会叫 OEM CodePage,如果是英文,那就会是 437,不是 1252。
http://msdn.microsoft.com/en-us/goglobal/cc305156
反正文字档或者说字串本身是无属性的,你的作业系统用什麽设定,他就用
哪套编码去解读。
ANSI 才是目前 Windows 的主流,看到任何跟 OEM 有关的字眼,你自动认定
与你无关,古早的东西,你用不到,这样就好了。
严格来说,真正的主流是 Unicode,只是 Windows 预设的文字档都会用 ANSI 编码。
一份文字文件,在 Windows 下其实开启时,其实会先判断是否为 Unicode 文字档。
如果是 ANSI 编码那就照之前说的,看作业系统的 CodePage 值来解读。
如果文件是 Unicode 编码,那代表不管用什麽语言的作业系统去看此文件,
都能看到相同的内容,因为大家都用同样的一套编码方式。
详细的,自己 google 吧自己 google 吧自己 google 吧
########
追加补充
根据这篇文章
http://support.microsoft.com/kb/65124/zh-tw
中说的
One of the main problems developers face when writing international
Windows-based applications is handling characters sets. It is very
important to understand ANSI and OEM.
ANSI is the character set used internally by Windows and its
applications. Windows does not recognize any character set other than
ANSI.
OEM is defined by Windows as the character set used by MS-DOS. The term
"OEM" does not refer to a specific character set; instead, it refers
to any of the different character sets (code pages) that can be
installed and used by MS-DOS.
Because Windows runs on top of MS-DOS, there must be a layer between
Windows and MS-DOS that performs translations between ANSI and OEM. When
Windows is first installed, the Windows Setup program looks at the
MS-DOS-installed character set, and then installs the correct ANSI-OEM
translation tables and Windows OEM fonts.
Windows-based applications should use the Windows functions AnsiToOem()
and OemToAnsi() when transferring information to and from MS-DOS. Also,
applications should use the correct character set when creating
filenames.
首先档案名称的部份别管他,因为旧的档案系统才会用到非 Unicod 的东西,
自从 NTFS 档案系统变成主流开始,档案名称的内部记录,就是用 Unicode 储存。
该文提到 Windows runs on top of MS-DOS 这应该是指旧的 Windows 98 时代左右
的状况,现在的 Windows 完全跟 MS-DOS 毫无任何关系。
现在的 Windows 里面的命令提示字元,只是 Windows 系统附带的一个程式,
这个程式的功能类似 VMware, VirtualBox 都是虚拟机器,严格来说,是 DOS 模拟器。
然後你也别指望这个 DOS 模拟器里面的东西,能跟 Linux 里的终端机一样,
很完整很顺畅的支援 Unicode。
他就只是个阳春的模拟器,能让你玩玩 DOS 时代的 H-Game 过过瘾就顶天了。
这个 DOS 模拟器,在繁体中文 Windows 他预设就会使用 OEM codepage 950
http://msdn.microsoft.com/en-us/goglobal/cc305155
(繁体中文的 Codepage 从 OEM 到 ANSI 都一样是 CP950)
所以 printf("你好"); 在预设情况下,是可以正常显示出中文来的。
你可以用 chcp 437 指令切换到英文,或用 chcp 65001 切换到 UTF-8,
反正还是一个重点,这模拟器只是阳春的产品,会有 Bug 也会有某些地方怪怪的。
比如打 chcp 936,抱歉,无法切换到大陆人的简体中文。
所以现在就没有 MS-DOS,那就不需要转换 OEM 来转换 OEM 去,
没有人要跟你玩了,你去 google 看能找到几篇还在扯这两个函数的。
看是讨论 "我们发财了" 的文章比较多,还是讨论这两个函数的文章比较多。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 124.8.134.73
1F:推 MOONRAKER:赞 118.163.12.174 09/18 19:31
2F:推 jonce007:感谢p大回应。oem忘了它就对了吗? 118.161.74.164 09/18 22:49
3F:→ purpose:嗯 124.8.134.73 09/18 23:27
※ 编辑: purpose 来自: 124.8.134.73 (09/19 00:22)
4F:推 CB34:推一个 118.160.195.47 01/13 23:52