If the method succeeds, the return value is the number of
characters copied into the string buffer, not including the
terminating null character. If the method fails,
the return value is zero. To get extended error information,
call GetLastError.
Port numbers can be assigned human readable service names to make
them easier to reference. This method will return the name assigned
to the specified port number. If the port number does not have an
assigned name, this method will return zero and the last error code
will be set to ST_ERROR_INVALID_SERVICE_NAME.
Most applications should use DNS_SERVICE_ANY to return the service
name assigned to a port number. Services typically use the same name
and port number regardless of the protocol used to establish a
connection with them. However, specifying a protocol can enable your
application to determine if the service supports the protocol. For
example, calling this method with port number 21 and
DNS_SERVICE_UDP would result in an error because FTP only supports
TCP connections.
Service names are assigned by the Internet Assigned Numbers
Authority (IANA) and the database of recognized service names can be
returned by calling the GetDefaultServicesFile
method. The default location for this file is in a protected area of
the Windows operating system and can only be modified by a process
with administrative privileges.