蓝牙配对

p89787259 2011-04-21 10:57:14
谁有用过btdrt.dll 写过蓝牙配对的?能告诉详细的流程或者发份代码给我 谢谢 p89787259@163.com
...全文
74 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fqipkh 2011-04-25
  • 打赏
  • 举报
回复
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;
}
烂番 2011-04-25
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20110419/10/eb77ba50-526a-43ba-b39c-89ddabc54cb6.html

1,068

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧