phobos/tango on win32: please drop ANSI "support"

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Feb 14 12:03:50 PST 2007


BCS wrote:
> Lionello Lunesu wrote:
> 
>> Both Phobos and Tango pretend utf8 is valid for calling ANSI methods 
>> from the Windows' API. Obviously, it's not. The correct way is to 
>> convert the utf8 string to the code-page expected by the call, or 
>> convert them to unicode.
>>
>> I'd like to suggest the latter. Let's drop the ANSI support for Win32 
>> altogether. Unicode is supported since Windows 95 OSR-2 (if I'm not 
>> mistaken) and converting utf8 to ANSI is more expensive than 
>> converting it utf8 to utf16 (which is what Windows 2000 and up convert 
>> to internally anyway). No more "bool UseWFuncs". And converting utf8 
>> to utf16 using MultiByteToWideChar would also take care of the 
>> 0-terminator.
>>
>> There, I've said it.
>>
>> L.
> 
> 
> Do you mean ASCII?

Perhaps these would be edifying:

http://en.wikipedia.org/wiki/Windows_code_page
http://en.wikipedia.org/wiki/Windows-1252

In short, when someone says "ANSI" in reference to Windows or the 
Windows API, they mean the stuff in the above articles (which isn't 
actually an ANSI standard at all). Those are flat 8-bit encodings, and 
storing them in a UTF-8 datatype will only cause grief. As Lionello 
points out, modern versions of Windows use UTF-16 internally. (Although 
originally it was just UCS-2, and most Windows fonts don't know about 
anything beyond those two bytes.)

I agree with Lionello: UTF-8 is a terrible thing to call the Windows API 
with. When dealing with the Windows API in D, it is best to stick with 
wchar[].

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list