Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function causes Services.exe to listen on the specified socket address and map network requests on the socket to the specified service instance.

Syntax

BOOL ServiceAddPort(
  HANDLE 
hService,
  SOCKADDR
 *pSockAddr,
  INT
 cbSockAddr,
  INT
 iProtocol,
  WCHAR
 szRegWritePath
);

Parameters

hService

[in] Handle to the service instance that the socket is to be associated with.

pSockAddr

[in] Pointer to the network address to listen on.

cbSockAddr

[in] Length of pSockAddr.

iProtocol

[in] Protocol of the socket.

szRegWritePath

[in] Optional. String that contains the registry key associated with given service to pSockAddr, cbSockAddr, and iProtocol. Specifying szRegWritePathwill ensure that the address specified in the function will automatically be listened on whenever the server initializes. The service must have been started with ActivateService, not RegisterService, for this to function.

Return Value

A nonzero value indicates success. A value of zero indicates failure. To get extended error information, call GetLastError.

Remarks

On calling ServiceAddPort, the values for pSockAddr, cbSockAddr, and iProtocolwill be used to create a socket and bind and listen on the specified address.

When an incoming connection request takes place, Services.exe will call accepton the socket and pass it to the xxx_IOControl (Services.exe)exported from the service, setting the function's dwCodeparameter to IOCTL_SERVICE_CONNECTIONand passing the socket in the parameter pBufIn.

Super service sockets associated with a given service can be stopped with a call to ServiceUnbindPorts. They will also be stopped when the service is stopped during a call to DeregisterServiceand when DeviceIoControlor ServiceIoControlis called specifying the parameter IOCTL_SERVICE_STOP.

Requirements

Header service.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also