Last active
February 3, 2023 20:23
-
-
Save 400-17/cf4f2b03ae748e714dd16f3839f719f4 to your computer and use it in GitHub Desktop.
check bluetooth_radio and bluetooth_device (windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include<windows.h> | |
#include<bluetoothapis.h> | |
#include<iostream> | |
#pragma comment(lib,"Bthprops") | |
int check_device(BLUETOOTH_DEVICE_SEARCH_PARAMS p_dev, BLUETOOTH_DEVICE_INFO i_dev,int count) { | |
int check_count = 0; | |
HBLUETOOTH_DEVICE_FIND f_dev = BluetoothFindFirstDevice(&p_dev, &i_dev); | |
if (f_dev) { | |
do { | |
std::wcout << " " << check_count << "_" << i_dev.szName << std::endl; | |
check_count++; | |
} while (BluetoothFindNextDevice(f_dev, &i_dev)); | |
BluetoothFindDeviceClose(f_dev); | |
} | |
std::wcout << "end check func\n" << std::endl; | |
count++; | |
return count; | |
} | |
int main() | |
{ | |
BLUETOOTH_FIND_RADIO_PARAMS para_radio = { 0 }; | |
para_radio.dwSize = sizeof(BLUETOOTH_FIND_RADIO_PARAMS); | |
HANDLE radio = 0; | |
HBLUETOOTH_RADIO_FIND find = BluetoothFindFirstRadio(¶_radio, &radio); | |
int cnt = 0; | |
if (find) { | |
std::wcout << "my bluetooth" << std::endl; | |
do { | |
BLUETOOTH_RADIO_INFO info = { 0 }; | |
info.dwSize = sizeof(BLUETOOTH_RADIO_INFO); | |
BluetoothGetRadioInfo(radio, &info); | |
std::wcout << info.szName << std::endl; | |
CloseHandle(radio); | |
} while (BluetoothFindNextRadio(find, &radio)); | |
} | |
std::wcout << "end my bluetooth\n" << std::endl; | |
//device | |
BLUETOOTH_DEVICE_SEARCH_PARAMS para_dev = { 0 }; | |
para_dev.fReturnAuthenticated = TRUE; | |
para_dev.fReturnRemembered = TRUE; | |
para_dev.fReturnConnected = TRUE; | |
para_dev.fReturnUnknown = TRUE; | |
para_dev.fIssueInquiry = TRUE; | |
para_dev.cTimeoutMultiplier = 5; | |
para_dev.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS); | |
BLUETOOTH_DEVICE_INFO infodev = { 0 }; | |
infodev.dwSize = sizeof(BLUETOOTH_DEVICE_INFO); | |
//case1 | |
std::wcout << cnt << "_check fReturnConnected and fReturnUnknown is TRUE" << std::endl; | |
cnt=check_device(para_dev, infodev,cnt); | |
//case2 | |
para_dev.fReturnConnected = FALSE; | |
std::wcout << cnt << "_check fReturnConnected is FALSE and fReturnUnknown is TRUE" << std::endl; | |
cnt=check_device(para_dev, infodev,cnt); | |
//case3 | |
para_dev.fReturnUnknown = FALSE; | |
std::wcout << cnt << "_check fReturnConnected and fReturnUnknown is FALSE" << std::endl; | |
cnt = check_device(para_dev, infodev, cnt); | |
//case4 | |
para_dev.fReturnConnected = TRUE; | |
std::wcout << cnt << "_check fReturnConnected is TRUE and fReturnUnknown is FALSE" << std::endl; | |
cnt = check_device(para_dev, infodev, cnt); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment