蓝牙配对

 

//所有获取到的蓝牙配对
void GetMatchRedio()
{
	CString strVal(L"");
	m_vBluetoothInfo.clear();
	for (int i = 0; i < m_BlueTooth.m_arrRemote.GetSize(); ++i)
	{
		//获取蓝牙信息
		BLUETOOTH_DEVICE_INFO bdi;
		//获取蓝牙信息
		if (!GetRemoteRadioInfo(i, bdi))
		{
			break;
		}

		BLUETOOTH_INFO BlueInfo;
		BlueInfo.btAddr = bdi.Address.ullLong;
		BlueInfo.strName = m_BlueTooth.m_arrRemote[i].sName;
		BlueInfo.strAddr = m_BlueTooth.AddrToStr(bdi.Address.rgBytes);
		m_vBluetoothInfo.push_back(BlueInfo);
		strVal.Format(L"MAC:%s 设备名称:%s", m_BlueTooth.AddrToStr(bdi.Address.rgBytes), BlueInfo.strName);
		SetTips(strVal);
	}
}
//配对某个蓝牙
BOOL MatchReadiByNO(int nNo)
{
    BLUETOOTH_DEVICE_INFO bdi;
    //获取蓝牙信息
    if (!GetRemoteRadioInfo(nNo, bdi))
    {
        return FALSE;
    }
    if (!bdi.fAuthenticated) //未自动配对则密码配对
    {
        SetTips(L"正蓝牙密码配对。。。");
        t_RemoteBthDevInfo RemoteBthDevInfo;
        RemoteBthDevInfo.Address.ullLong = bdi.Address.ullLong;
        m_BlueTooth.EnumerateInstalledServices(RemoteBthDevInfo);
        DWORD nRes = 100;
        //配对密码1234
        if (nRes = BluetoothAuthenticateDevice(NULL, m_hLocalRadio, &bdi, L"1234", 4) != ERROR_SUCCESS)
        {
            SetTips(L"蓝牙密码配对失败。");
            return FALSE;;
        }
        bdi.fAuthenticated = TRUE;
        BluetoothUpdateDeviceRecord(&bdi);
    }
    return TRUE;
}

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值