zoukankan      html  css  js  c++  java
  • 蓝牙搜索

    /********************************************************************
        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();
    }
  • 相关阅读:
    List of Examples Converting XNA 3.1 to XNA 4.0
    XNA程序开发常用到的一些代码汇总
    在WCF中使用Flag Enumerations
    能飞过海洋的却只有海鸥【转载】
    Variant类型转换成CString代码
    一种漂亮的自绘菜单
    转 在OpenCV中用cvCalibrateCamera2进行相机标定(附程序)
    COM组件设计与应用之VC6中用ATL写组件
    vc的菜单,工具栏
    (餐饮)写一些开店的经验转
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/4102892.html
Copyright © 2011-2022 走看看