CSocketWrench::HostNameToUnicode Method  
 
INT HostNameToUnicode(
  LPCTSTR lpszHostName,  
  LPTSTR lpszUnicodeName,  
  INT nMaxLength  
);
INT HostNameToUnicode(
  LPCTSTR lpszHostName,  
  CString& strUnicodeName  
);

The HostNameToUnicode method converts the canonical form of a host name to its Unicode version.

Parameters

lpszHostName
Pointer to the host name as a null-terminated string. This parameter cannot be a NULL pointer or a zero length string.
lpszUnicodeName
Pointer to the string buffer that will contain the original Unicode version of the host name, including the terminating null character. It is recommended that this buffer be at least 256 characters in size. This parameter cannot be a NULL pointer. An alternate version of this method accepts a reference to a CString object.
nMaxLength
The maximum number of characters that can be copied to the lpszUnicodeName string buffer. This parameter cannot be zero, and must include the terminating null character.

Return Value

If the method succeeds, the return value is the number of characters copied into the string buffer. If the method fails, the return value is INET_ERROR. To get extended error information, call GetLastError.

Remarks

The HostNameToUnicode method will convert the encoded ASCII version of a host name to its Unicode version. Although any valid host name is accepted by this method, it is intended to convert a Punycode encoded host name to its original Unicode character encoding.

If the application is compiled using the Unicode character set, the value returned in lpszUnicodeName will be a Unicode string using UTF-16 encoding. If the ANSI character set is used, the value returned will be a Unicode string using UTF-8 encoding. To display a UTF-8 encoded host name, your application will need to convert it to UTF-16 using the MultiByteToWideChar function.

Although this method performs checks to ensure that the lpszHostName parameter is in the correct format and does not contain any illegal characters or malformed encoding, it does not validate the existence of the domain name. To check if the host name exists and has a valid IP address, use the GetHostAddress method.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cswsock10.h
Import Library: cswskv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

GetHostAddress, NormalizeHostName