蓝牙搜索
/******************************************************************** created: 2010/01/29 file base: wBlue file ext: c author: TODY_GUO Revision: 1.0.0 purpose: Searching Bluetooth Devices.... this just for MS BT Driver *********************************************************************/ #include <stdio.h> #include <conio.h> #include <Windows.h> #include <bthdef.h> #include <BluetoothAPIs.h> int search_bluetooth_device() { BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) }; BLUETOOTH_DEVICE_SEARCH_PARAMS btdp = { sizeof(btdp) }; BLUETOOTH_DEVICE_INFO Devinfo; BLUETOOTH_RADIO_INFO RadioInfo; HANDLE hRadio; char blueT_Name[256]={'/0'}; HBLUETOOTH_RADIO_FIND hFind_R ; HBLUETOOTH_DEVICE_FIND hFind_D; printf("Searching Local Bluetooth(s)..."); hFind_R = BluetoothFindFirstRadio(&btfrp,&hRadio); if (NULL != hFind_R) { RadioInfo.dwSize = sizeof(RadioInfo); do { printf(" Found!/n"); if( ERROR_SUCCESS == BluetoothGetRadioInfo(hRadio, &RadioInfo)) { wcstombs(blueT_Name,RadioInfo.szName,sizeof(blueT_Name)); printf("-----------------------------------------/n"); printf("Bluetooth Name/t/tMAC Address/n"); printf("-----------------------------------------/n"); printf("%-15S/t/t%02x:%02x:%02x:%02x:%02x:%02x",RadioInfo.szName, RadioInfo.address.rgBytes[5], RadioInfo.address.rgBytes[4], RadioInfo.address.rgBytes[3], RadioInfo.address.rgBytes[2], RadioInfo.address.rgBytes[1], RadioInfo.address.rgBytes[0]); } else { printf("Local Get Info Fail."); return 1; } // Find near Device... memset(&btdp,0,sizeof(btdp)); btdp.hRadio = hRadio; btdp.fReturnAuthenticated = TRUE; btdp.fReturnRemembered = TRUE; btdp.dwSize = sizeof(btdp); btdp.cTimeoutMultiplier = 10; btdp.fIssueInquiry = TRUE; btdp.fReturnUnknown = TRUE; Devinfo.dwSize = sizeof(Devinfo); hFind_D = BluetoothFindFirstDevice(&btdp,&Devinfo); if ( hFind_D != NULL) { do { if ( ERROR_SUCCESS == BluetoothGetDeviceInfo(hRadio,&Devinfo)) { printf("/n%-15S/t/t%02x:%02x:%02x:%02x:%02x:%02x",Devinfo.szName, Devinfo.Address.rgBytes[5], Devinfo.Address.rgBytes[4], Devinfo.Address.rgBytes[3], Devinfo.Address.rgBytes[2], Devinfo.Address.rgBytes[1], Devinfo.Address.rgBytes[0]); } else { printf("Remote Get Info fail."); return 1; } } while(BluetoothFindNextDevice(hFind_D,&Devinfo)); BluetoothFindDeviceClose(hFind_D); } else { printf("/nRemote Bluetooth Not Found!/n"); return 1; } } while(BluetoothFindNextRadio(hFind_R,&hRadio)); BluetoothFindRadioClose(hFind_R); // Close Local Function } else { printf(" not Found!/n"); return 1; } return 0; } int main(int argc, char* argv[]) { return search_bluetooth_device(); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2008-11-17 Hack Attack : Install Leopard on your PC in 3 easy steps!