unicodewinsockmsdn

Why does MSDN advise use of unicode functions over ansi functions for winsock calls?


MSDN advises:

The getaddrinfo function is the ANSI version of a function that provides protocol-independent translation from host name to address. The Unicode version of this function is GetAddrInfoW. Developers are encouraged to use the GetAddrInfoW Unicode function rather than the getaddrinfo ANSI function.

Encouragement is fine and all, but is there any reason to do this? I mean, can hostnames contain non-ansi characters? If so, is this a feature exclusive to IPv6, or can IPv4 hostnames also contain unicode characters?


Solution

  • Microsoft is just trying to get everyone away from Ansi in general, that's all. They recommend using Unicode for everything, especially since Windows itself is based on Unicode (and has been for a long long time). But yes, as Jason said, hostnames can contain Unicode characters via Punycode encoding, which is backwards compatible with the existing Ansi-based DNS system.