BluetoothFindNextDevice can't find BLE device

猿小白 1 Reputation point
2020-09-01T10:19:35.99+00:00

BluetoothFindNextDevice and BluetoothFindFirstDevice functions can't find BLE mouse. I am sure the mouse is in discovering state. I can find the mouse via System Settings-> Bluetooth. How to find BLE device programmatically?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,498 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rita Han - MSFT 2,161 Reputation points
    2020-09-03T08:55:47.22+00:00

    Hello,

    The following code sample can find BLE mouse for me. You can have a try.

    BOOL FindDevice()
    {
    wcout.imbue(locale(""));
    
    HBLUETOOTH_RADIO_FIND hbf = NULL;
    HANDLE hbr = NULL;
    HBLUETOOTH_DEVICE_FIND hbdf = NULL;
    BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) }; 
    BLUETOOTH_RADIO_INFO bri = { sizeof(BLUETOOTH_RADIO_INFO) }; 
    BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS) };
    BLUETOOTH_DEVICE_INFO btdi = { sizeof(BLUETOOTH_DEVICE_INFO) };  
    
    hbf = BluetoothFindFirstRadio(&btfrp, &hbr); 
    
    bool brfind = hbf != NULL;
    
    UINT radioCount = 0;
    
    while (brfind)
    {
    if (BluetoothGetRadioInfo(hbr, &bri) == ERROR_SUCCESS)
    {
    cout << "\n ### " << radioCount++ << ", Bluetooth radio information:";
    cout << "\n Class of device: 0x" << uppercase << hex << bri.ulClassofDevice;
    wcout << ", Name:" << bri.szName << endl;  
    
    btsp.hRadio = hbr;  
    btsp.fReturnAuthenticated = TRUE;
    btsp.fReturnConnected = FALSE;
    btsp.fReturnRemembered = TRUE;
    btsp.fReturnUnknown = TRUE;
    btsp.fIssueInquiry = TRUE;
    btsp.cTimeoutMultiplier = 20;
    hbdf = BluetoothFindFirstDevice(&btsp, &btdi);
    
    bool bfind = hbdf != NULL;
    
    UINT deviceCount = 0;
    
    while (bfind)
    {
    cout << "\n *** "<< deviceCount++ << ", Bluetooth device information:";
    wcout << "\n [Name]:" << btdi.szName;  
    cout << ", [Address]:0x" << uppercase << hex << btdi.Address.ullLong;
    //printf(", Authenticated: %d, Connected: %d, Remembered: %d \n", btdi.fAuthenticated, btdi.fConnected, btdi.fRemembered);
    cout << ", Authenticated:" << (btdi.fAuthenticated ? TRUE : FALSE);
    cout << ", Connected:" << (btdi.fConnected ? TRUE : FALSE);
    cout << ", Remembered:" << (btdi.fRemembered ? TRUE : FALSE);
    
    bfind = BluetoothFindNextDevice(hbdf, &btdi);
    }
    }
    
    if(hbf != NULL)
        brfind = BluetoothFindNextRadio(hbf, &hbr);
    }
    
    if(NULL != hbf)
        BluetoothFindRadioClose(hbf);
    
    return TRUE;
    }
    

    Thank you!

    0 comments No comments