蓝牙配对
谁有用过btdrt.dll 写过蓝牙配对的?能告诉详细的流程或者发份代码给我 谢谢 p89787259@163.com
[解决办法]
int FindDevices (PMYBTDEVICE pbtDev, int *pnDevs) {
DWORD dwFlags, dwLen;
HANDLE hLookup;
int i, rc, nMax = *pnDevs;
*pnDevs = 0;
// Create inquiry blob to limit time of search
BTHNS_INQUIRYBLOB inqblob;
memset (&inqblob, 0, sizeof (inqblob));
inqblob.LAP = BT_ADDR_GIAC; // Default GIAC
inqblob.length = 4; // 4 * 1.28 = 5 seconds
inqblob.num_responses = nMax;
// Create blob to point to inquiry blob
BLOB blob;
blob.cbSize = sizeof (BTHNS_INQUIRYBLOB);
blob.pBlobData = (PBYTE)&inqblob;
// Init query
WSAQUERYSET QuerySet;
memset(&QuerySet,0,sizeof(WSAQUERYSET));
QuerySet.dwSize = sizeof(WSAQUERYSET);
QuerySet.dwNameSpace = NS_BTH;
QuerySet.lpBlob = &blob;
// Start query for devices
rc = WSALookupServiceBegin (&QuerySet, LUP_CONTAINERS, &hLookup);
if (rc) return rc;
PBYTE pOut = (PBYTE)LocalAlloc (LPTR, MYBUFFSIZE);
if (!pOut) return -1;
WSAQUERYSET *pQueryResult = (WSAQUERYSET *)pOut;
for (i = 0; i < nMax; i++) {
dwLen = MYBUFFSIZE;
dwFlags = LUP_RETURN_NAME | LUP_RETURN_ADDR;
rc = WSALookupServiceNext (hLookup, dwFlags, &dwLen, pQueryResult);
if (rc == SOCKET_ERROR) {
rc = GetLastError();
break;
}
// Copy device name
if (pQueryResult->lpszServiceInstanceName)
StringCchCopy (pbtDev[i].szName, dim (pbtDev[i].szName),
pQueryResult->lpszServiceInstanceName);
else
pbtDev[i].szName[0] = TEXT('\0');
// Copy bluetooth device address
SOCKADDR_BTH *pbta;
pbta = (SOCKADDR_BTH *)pQueryResult->lpcsaBuffer->RemoteAddr.lpSockaddr;
pbtDev[i].btaddr = pbta->btAddr;
}
if (rc == WSA_E_NO_MORE) rc = 0;
*pnDevs = i;
WSALookupServiceEnd (hLookup);
LocalFree (pOut);
return rc;
}