首先 Bthprops.lib及 对应的头文件BluetoothAPIs.h这个库很重要,Windows蓝牙适配器自带的驱动程序,就是调用这个库中的接口实现的,
详细说明可以查阅msdn。
参考博客:
http://blog.sina.com.cn/s/blog_648d306d0102vjq5.html
http://blog.youkuaiyun.com/maxwoods/article/details/41290015
这里仅做一下记录。。。
实际工作中遇到问题还未解决。。。
2016-11-10 利用Bthprops.lib及 对应的头文件BluetoothAPIs.h这个库, 搜索蓝牙设备,并配对,虽然并没有达到自己想要的效果,也在这里记录一下:
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream>
#include <Winsock2.h>
#include <bthsdpdef.h>
#include <BluetoothAPIs.h>
#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"Bthprops.lib")
using namespace std;
int main(void)
{
wcout.imbue(locale(""));
HBLUETOOTH_RADIO_FIND hbf = NULL;
HANDLE hbr = NULL;
HBLUETOOTH_DEVICE_FIND hbdf = NULL;
BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };
BLUETOOTH_RADIO_INFO bri = { sizeof(BLUETOOTH_RADIO_INFO)};
BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS) };
BLUETOOTH_DEVICE_INFO btdi = { sizeof(BLUETOOTH_DEVICE_INFO) };
hbf=BluetoothFindFirstRadio(&btfrp, &hbr);
bool brfind = hbf != NULL;
while (brfind)
{
if (BluetoothGetRadioInfo(hbr, &bri) == ERROR_SUCCESS)
{
cout << "Class of device: 0x" << uppercase << hex << bri.ulClassofDevice << endl;
wcout <<"Name:"<< bri.szName << endl;
cout <<"Manufacture:0x"<< uppercase << hex << bri.manufacturer << endl;
cout << "Subversion:0x" << uppercase << hex << bri.lmpSubversion << endl;
//
btsp.hRadio = hbr;
btsp.fReturnAuthenticated = FALSE;
btsp.fReturnConnected = FALSE;
btsp.fReturnRemembered = TRUE;
btsp.fReturnUnknown = TRUE;
btsp.cTimeoutMultiplier = 3000;
hbdf=BluetoothFindFirstDevice(&btsp, &btdi);
bool bfind = hbdf != NULL;
while (bfind)
{
wcout << "[Name]:" << btdi.szName;
cout << ",[Address]:0x" << uppercase << hex << btdi.Address.ullLong << endl;
char m_char[256];
int len = WideCharToMultiByte(CP_ACP,0,btdi.szName,wcslen(btdi.szName),m_char,256,NULL,NULL);
m_char[len] = '\0';
if (strcmp("设备名", m_char) == 0)
{
/*btdi.fAuthenticated = TRUE;
nRet = BluetoothUpdateDeviceRecord(&btdi);*/
nRet = BluetoothAuthenticateDevice(
NULL,
NULL,
&btdi,
NULL,
0
);
nRet += 0;
}
bfind=BluetoothFindNextDevice(hbdf, &btdi);
}
BluetoothFindDeviceClose(hbdf);
}
CloseHandle(hbr);
brfind=BluetoothFindNextRadio(hbf, &hbr);
}
BluetoothFindRadioClose(hbf);
_getch();
return 0;
}