• 蓝牙搜索


    /********************************************************************
        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();
    }
  • 相关阅读:
    排序算法之快速排序
    设计模式之原型模式
    设计模式之门面模式
    第五十四课 树中节点的插入操作
    第五十三课 树中节点的查找操作
    第五十二课 树的存储结构与实现
    第五十一课 树的定义与操作
    第五十课 排序的工程应用示例
    第四十九课 归并排序和快速排序
    第四十八课 冒泡排序和希尔排序
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/4102892.html
Copyright © 2020-2023  润新知