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