If the method succeeds, the host name is valid and the return value
will be non-zero. If the method fails, the host name could not be resolved
to an IP address and the return value will be zero. To get extended error
information, call the GetLastError method.
The ValidateHostName method provides a convenient way
to determine if a host name is valid by attempting to resolve the name
into an IP address. It is similar to calling the
NormalizeHostName method to obtain the canonical form of the
host name, calling GetAddress to obtain the IP address and
then calling FormatAddress to return the string
representation of the host's IP address.
If the Unicode version of this method is used, any non-ASCII
characters in the host name will be automatically encoded into a
compatible format and then resolved to an IP address. If you are
unsure if an internationalized domain name will be specified as the
host name, it is recommended you use the Unicode version.
The lpszHostName parameter can only specify a host name or
IP address and cannot be a URL. If you want your application to
support providing a URL in addition to a host name, use the
GetUrlHostName method to extract the host name from the
URL. You can then provide the host name to this method to obtain its
IP address.
If the lpszHostName parameter specifies a valid IPv4 or
IPv6 address string instead of a host name, this method will return
a copy of that IP address in the buffer provided by the caller. This
allows the method to be used in cases where a user may input either
a host name or IP address. To determine if the IP address has a
corresponding host name, use the GetHostName method.