WSALookupServiceNext

The Windows Sockets WSALookupServiceNext function is called after obtaining a handle from a previous call to WSALookupServiceBegin in order to retrieve the requested service information.

The provider will pass back a WSAQUERYSET structure in the lpqsResults buffer. The client should continue to call this function until it returns WSA_E_NOMORE, indicating that all of WSAQUERYSET has been returned.

INT WSALookupServiceNext (
  HANDLE hLookup,        
  DWORD dwControlFlags,  
  LPDWORD lpdwBufferLength,  
  LPWSAQUERYSET lpqsResults  
);
 

Parameters

hLookup
[in] A handle returned from the previous call to WSALookupServiceBegin.
dwControlFlags
[in] Flags to control the next operation. Currently only LUP_FLUSHPREVIOUS is defined as a means to cope with a result set which is too large. If an application does not wish to (or cannot) supply a large enough buffer, setting LUP_FLUSHPREVIOUS instructs the provider to discard the last result set - which was too large - and move on to the next set for this call.
lpdwBufferLength
[in/out] On input, the number of bytes contained in the buffer pointed to by lpqsResults. On output, if the function fails and the error is WSAEFAULT, then it contains the minimum number of bytes to pass for the lpqsResults to retrieve the record.
lpqsResults
[out] A pointer to a block of memory, which will contain one result set in a WSAQUERYSET structure on return.

Remarks

The dwControlFlags specified in this function and the ones specified at the time of WSALookupServiceBegin are treated as "restrictions" for the purpose of combination. The restrictions are combined between the ones at WSALookupServiceBegin time and the ones at WSALookupServiceNext time. Therefore the flags at WSALookupServiceNext can never increase the amount of data returned beyond what was requested at WSALookupServiceBegin, although it is NOT an error to specify more or fewer flags. The flags specified at a given WSALookupServiceNext apply only to that call.

The dwControlFlags LUP_FLUSHPREVIOUS and LUP_RES_SERVICE are exceptions to the "combined restrictions" rule (because they are "behavior" flags instead of "restriction" flags). If either of these flags are used in WSALookupServiceNext they have their defined effect regardless of the setting of the same flags at WSALookupServiceBegin.

For example, if LUP_RETURN_VERSION is specified at WSALookupServiceBegin the service provider retrieves records including the "version". If LUP_RETURN_VERSION is NOT specified at WSALookupServiceNext, the returned information does not include the "version", even though it was available. No error is generated.

Also for example, if LUP_RETURN_BLOB is NOT specified at WSALookupServiceBegin but is specified at WSALookupServiceNext, the returned information does not include the private data. No error is generated.

Query Results

The following table describes how the query results are represented in the WSAQUERYSET structure.

WSAQUERYSET Field Name Result Interpretation
dwSize Will be set to sizeof(WSAQUERYSET). This is used as a versioning mechanism.
DwOuputFlags RESULT_IS_ALIAS flag indicates this is an alias result.
LpszServiceInstanceName Referenced string contains service name.
LpServiceClassId The GUID corresponding to the service class.
LpVersion References version number of the particular service instance.
LpszComment Optional comment string supplied by service instance.
DwNameSpace Name space in which the service instance was found.
LpNSProviderId Identifies the specific name space provider that supplied this query result.
LpszContext Specifies the context point in a hierarchical name space at which the service is located.
DwNumberOfProtocols Undefined for results.
LpafpProtocols Undefined for results, all needed protocol information is in the CSADDR_INFO structures.
LpszQueryString When dwControlFlags includes LUP_RETURN_QUERY_STRING, this field returns the unparsed remainder of the lpszServiceInstanceName specified in the original query. For example, in a name space that identifies services by hierarchical names that specify a host name and a file path within that host, the address returned might be the host address and the unparsed remainder might be the file path. If the lpszServiceInstanceName is fully parsed and LUP_RETURN_QUERY_STRING is used, this field is NULL or points to a zero-length string.
DwNumberOfCsAddrs Indicates the number of elements in the array of CSADDR_INFO structures.
LpcsaBuffer A pointer to an array of CSADDR_INFO structures, with one complete transport address contained within each element.
LpBlob (Optional) This is a pointer to a provider-specific entity.

Return Values

The return value is zero if the operation was successful. Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSA_E_NO_MORE There is no more data available. In Windows Sockets version 2, conflicting error codes are defined for WSAENOMORE (10102) and WSA_E_NO_MORE (10110). The error code WSAENOMORE will be removed in a future version and only WSA_E_NO_MORE will remain. For Windows Sockets version 2, however, applications should check for both WSAENOMORE and WSA_E_NO_MORE for the widest possible compatibility with Name Space Providers that use either one.
WSA_E_CANCELLED A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. The data in the lpqsResults buffer is undefined. In Windows Sockets version 2, conflicting error codes are defined for WSAECANCELLED (10103) and WSA_E_CANCELLED (10111). The error code WSAECANCELLED will be removed in a future version and only WSA_E_CANCELLED will remain. For Windows Sockets version 2, however, applications should check for both WSAECANCELLED and WSA_E_CANCELLED for the widest possible compatibility with Name Space Providers that use either one.
WSAEFAULT The lpqsResults buffer was too small to contain a WSAQUERYSET set.
WSAEINVAL One or more required parameters were invalid or missing.
WSA_INVALID_HANDLE The specified Lookup handle is invalid.
WSANOTINITIALIZED The WS2_32.DLL has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
WSANO_DATA The name was ound in the database, but no data matching the given restrictions was located.
WSASERVICE_NOT_FOUND No such service is known. The service cannot be found in the specified name space.
WSA NOT ENOUGH MEMORY There was insufficient memory to perform the operation.

QuickInfo

  Windows NT: Yes
  Windows: Yes
  Windows CE: Unsupported.
  Header: Declared in winsock2.h.
  Import Library: Link with ws2_32.lib.

See Also

WSALookupServiceBegin, WSALookupServiceEnd