对wince应用程序的编写,以用来搜索到周边的蓝牙设备,需要用到下面3个函数:
(1)
I WSALookupServiceBegin(
LPWSAQUERYSET pQuerySet,
DWORD dwFlags,
LPHANDLE lphLookup
);
这个函数主要用途是填充一个返回参数lphLookup,这是一个HANDLE,是给以后的两个函数用的。我们知道WSA开头的一般都是winsock函数,这个也不例外,只不过是它的第一个参数也就是搜索集pQuerySet设置成了蓝牙相关的。WSAQUERYSET结构如下:
typedef struct _WSAQuerySet {
DWORD dwSize;
LPTR lpszServiceInstanceName;
LPGUID lpServiceClassId;
LPWSAVERSI lpVersion;
LPTSTR lpszComment;
DWORD dwNameSpace;
LPGUID lpNroviderId;
LPTSTR lpszContext;
DWORD dwNumberOfProtocols;
LPAFPROTOCOLS lpafpProtocols;
LPTSTR lpszQueryString;
DWORD dwNumberOfCsAddrs;
LPCSA_INFO lpcsaBuffer;
DWORD dwOutputFlags;
LPBLOB lpBlob;
} WSAQUERYSET, *PWSAQUERYSETW;
不过对于蓝牙,我们一般这么用:
WSAQUERYSET btQuerySet;
memset(&btQuerySet;, 0,sizeof(btQuerySet;));
btQuerySet.dwSize = sizeof(btQuerySet;);
btQuerySet.dwNameSpace = NS_BTH;
btQuerySet.lpcsaBuffer = NULL;
再接着看下第二个参数dwFlags,它的取值如下:
LUP_CONTAINERS:
Specifies that device discovery is to be performed. If this flag is not set, service discovery will be performed instead.
LUP_RES_SERE:
Searches the local S database. Clear this flag to search for services on a peer device.
这里用的是LUP_CONTAINERS
If LUP_CONTAINERS is set, SDP performs a device inquiry to find other Bluetooth devices in the area. This function performs the query. The WSALookupServiceNext function retrieves the results one device at a time.
1 2 下一页> -电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。