What is Codepage 0?

我只是一个虾纸丫 提交于 2019-12-22 09:10:17

问题


I'm using the Delphi function

StringCodePage

I call it on a string returned by a COM function (Acrobat Annotation getContents - see my other posts) and it returns 0.

What is 0? Ansi?


回答1:


Code page 0 is CP_ACP, current Windows ANSI code page.

From Windows.pas:

{$EXTERNALSYM CP_ACP}
CP_ACP                   = 0;             { default to ANSI code page }

From MSDN:

CP_ACP

The current system Windows ANSI code page. This value can be different on different computers, even on the same network. It can be changed on the same computer, leading to stored data becoming irrecoverably corrupted. This value is only intended for temporary use and permanent storage should be done using UTF-16 or UTF-8 if possible.




回答2:


The only way StringCodePage() can return 0 is if you are passing in a blank AnsiString, thus returning its compile-time codepage affinity, or are passing in a non-blank AnsiString that has codepage 0 assigned to its payload. Delphi uses WideString for COM strings, and StringCodePage() will not return 0 for any string type except plain AnsiString. In D2009, the RTL did not do a very good job of storing the OS's actual run-time codepage into AnsiString payloads, so they commonly contained the compile-time codepage affinity of 0. That is functional in regards to string conversions, but it not very explicit. That was fixed in later Delphi versions so AnsiString payloads now contain the actual OS codepage that is determined at run-time.



来源:https://stackoverflow.com/questions/529502/what-is-codepage-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!