欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

蓝牙配对

程序员文章站 2022-03-15 14:25:01
//所有获取到的蓝牙配对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