Partager via


SOCKADDR_BTH (Windows Embedded CE 6.0)

1/6/2010

This structure defines the Bluetooth socket address.

Syntax

typedef struct _SOCKADDR_BTH {
  USHORT addressFamily;
  bt_addr btAddr;
  GUID serviceClassId;
  ULONG port;
} SOCKADDR_BTH, *PSOCKADDR_BTH;

Members

  • addressFamily
    Value that is set to the Bluetooth address family of AF_BTH.
  • btAddr
    Target device address of zero.
  • serviceClassId
    When connecting, the port must contain the server channel number of the RFCOMM service on the target device, or zero. If zero is specified, the serviceClassId field must contain a GUID for that service. In this case, Winsock performs an SDP query on the application's behalf, and then uses the resulting server channel.
  • port
    Service channel number or zero.

Remarks

You can use a family of macros defined in %_WINCEROOT%\Public\Common\SDK\Inc\Ws2bth.h to translate between bt_addr and NAP and SAP defined in the Bluetooth specifications.

GET_NAP()bt_addr)       // get NAP part of the address
GET_SAP(_bt_addr)       // get SAP part of the address
SET_NAP_SAP(_nap, _sap) // form the bt_addr from NAP and SAP

Example

bt_addr bt= SET_NAP_SAP(nap, sap);
wprintf(L"Connecting to %04x%08x.../n", GET_NAP(bt), GET_SAP(bt));

For servers, unless a fixed server channel is specified by a future Bluetooth profile specification, applications should use the value of 0.

If the port is 0, the port is allocated automatically. Server channels are a global resource. Bluetooth devices, for all applications, must share 31 channels between Winsock and Virtual COM ports.

If there is no service channel available, or the one specified is already reserved by another application, the call will fail. If the call succeeds, the service channel is reserved until the socket is closed. To retrieve the channel number for SDP registration, use the getsockname (Windows Sockets) function.

For a client, the port must contain the server channel number of the RFCOMM service on the target device, or 0. If 0 is specified, the serviceClassId field must contain a GUID for that service. In this case, Winsock performs an SDP query on the application's behalf, then uses the resulting server channel.

Requirements

Header ws2bth.h
Windows Embedded CE Windows CE .NET 4.0 and later

See Also

Reference

Bluetooth Application Development Structures

Other Resources

getsockname (Windows Sockets)