VC 蓝牙设备 编程


首先 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;  
}



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值