Bluetooth and WSALookupServiceBegin for Device Inquiry

This topic describes how to use the WSALookupServiceBegin function to perform an inquiry of both visible and ghosted devices. For more information, see Discovering Bluetooth Devices and Services.

The WSALookupServiceBegin function uses a WSAQUERYSET structure in its first parameter, lpqsRestrictions, to define search criteria. Bluetooth provides specific guidelines for use of the WSALookupServiceBegin function and WSAQUERYSET.

The following table lists restrictions that apply to the WSAQUERYSET structure passed to the lpqsRestrictions parameter when querying for devices.

WSAQUERYSET member Restriction
dwSize Set to sizeof(WSAQUERYSET).
lpBlob This member contains an optional pointer to a BLOB structure. If this member is specified, the valid device inquire parameters for LUP_FLUSHCACHE are as follows:
  • The cbSize member of the BLOB structure must be sizeof(BTH_QUERY_DEVICE).
  • The pBlobData member is a pointer to a BTH_QUERY_DEVICE structure, for which the LAP member is the Bluetooth inquiry access code, and the length member is the length, in seconds, of the inquiry.
dwNameSpace Set to NS_BTH.
Other members Other members of the WSAQUERYSET structure are ignored.

 

The flags listed in the following table are used in the dwControlFlags parameter to control the query results. The LUP_CONTAINERS and LUP_FLUSHCACHE flags are used by the WSALookupServiceBegin function; the rest of the flags are used in calls to the WSALookupServiceNext function.

Flag Result
LUP_CONTAINERS Specifies that the query purpose is to obtain a list of Bluetooth devices and not a list of services. This flag must be set.
LUP_FLUSHCACHE Triggers an inquiry of local devices or causes cached results from previous queries to be returned.
LUP_RETURN_TYPE Return the Bluetooth COD (class of device bits) directly in the lpServiceClassId member of the WSAQUERYSET structure. The COD is mapped to the Data1 member of the GUID.
LUP_RES_SERVICE Return information for the local Bluetooth address. This flag has an effect only if LUP_RETURN_ADDR is also specified.
LUP_RETURN_NAME Return the display name of the device in the lpszServiceInstanceName member of the WSAQUERYSET structure for each call to the WSALookupServiceNext function. This flag must also be specified to retrieve the name member of the BTH_DEVICE_INFO structure when specifying the LUP_RETURN_BLOB flag.
LUP_RETURN_ADDR Return a SOCKADDR_BTH structure that contains the 48-bit address of the peer in the lpcsaBuffer member of the WSAQUERYSET structure for each call to the WSALookupServiceNext function. Other members in the SOCKADDR_BTH structure will be empty.
LUP_RETURN_BLOB Return the BTH_DEVICE_INFO structure on each subsequent call to WSALookupServiceNext.
LUP_FLUSHPREVIOUS Skip the next available device, and return the device that follows it.

 

Bluetooth and WSALookupServiceBegin for Service Discovery

Bluetooth and WSALookupServiceNext

Bluetooth and WSAQUERYSET for Device Inquiry

Discovering Bluetooth Devices and Services

WSALookupServiceBegin

WSALookupServiceNext

WSALookupServiceEnd

BLOB

BTH_QUERY_DEVICE

SOCKADDR_BTH

WSAQUERYSET

Windows Sockets