Compartilhar via


ServiceAddPort

A version of this page is also available for

Windows Embedded CE 6.0 R3

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 szRegWritePath will 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 iProtocol will 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 accept on the socket and pass it to the xxx_IOControl (Services.exe) exported from the service, setting the function's dwCode parameter to IOCTL_SERVICE_CONNECTION and 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 DeregisterService and when DeviceIoControl or ServiceIoControl is 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

Reference

xxx_IOControl (Services.exe)
RegisterService
DeregisterService
ServiceIoControl

Other Resources

DeviceIoControl
Services.exe