问题描述
- 枚举蓝牙设备是什么意思,搜索吗?
-
求中文解析
DWORD dwWsaqsFlags = LUP_CONTAINERS | LUP_FLUSHCACHE | LUP_RETURN_NAME | LUP_RETURN_ADDR;HANDLE hService;
if(WSALookupServiceBegin(lpWsaqs, dwWsaqsFlags, &hService) != SOCKET_ERROR) { bool bFinished = false; while(!bFinished) { if(WSALookupServiceNext(hService, dwWsaqsFlags, &dwWsaqsLen, lpWsaqs) == NO_ERROR) { SOCKADDR_BTH saBth = (SOCKADDR_BTH)lpWsaqs->lpcsaBuffer->RemoteAddr.lpSockaddr; BTH_ADDR bthAddr = saBth->btAddr; _tprintf(_T("n发现蓝牙设备: n")); _tprintf(_T("------------------------n")); _tprintf(_T("NAP: 0x%04X SAP: 0x%08X 设备名称: %sn"), GET_NAP(bthAddr), GET_SAP(bthAddr), lpWsaqs->lpszServiceInstanceName); } else { // 错误处理 switch(WSAGetLastError()) { // 所给缓冲区过小,重新申请 case WSAEFAULT: HeapFree(GetProcessHeap(), 0, lpWsaqs); lpWsaqs = (LPWSAQUERYSET)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwWsaqsLen); break; // 没有更多蓝牙设备了 case WSA_E_NO_MORE: bFinished = true; break; default: //bFinished = true; break; } } } WSALookupServiceEnd( hService ); } // 释放资源 HeapFree(GetProcessHeap(), 0, lpWsaqs); WSACleanup(); return 0; }