次の方法で共有


SOCKADDR_BTH (Compact 2013)

3/26/2014

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
    Always set to AF_BTH.
  • btAddr
    Target device address or zero.
  • serviceClassId
    When connecting, the port must contain the server channel number of the RFCOMM service on the device, or zero. If zero is specified, the serviceClassId field must contain a GUID for that service. In this case, Winsock performs an Service Discovery Protocol (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 Non-significant Address Part (NAP) and Significant Address Part (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, 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 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

See Also

Reference

Bluetooth Application Development Structures

Other Resources

getsockname (Windows Sockets)