当前位置: 移动技术网 > 科技>人工智能>物联网 > 蓝牙配对

蓝牙配对

2020年11月26日  | 移动技术网科技  | 我要评论
//所有获取到的蓝牙配对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;...

 

//所有获取到的蓝牙配对
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;
}

 

本文地址:https://blog.csdn.net/weixin_37999268/article/details/110188509

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网