Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Codepage 0?

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?

like image 867
Toby Allen Avatar asked Feb 09 '09 19:02

Toby Allen


2 Answers

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.

like image 100
gabr Avatar answered Oct 20 '22 02:10

gabr


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.

like image 41
Remy Lebeau Avatar answered Oct 20 '22 03:10

Remy Lebeau