资源简介
此资源为文档与封装的蓝牙通信接口,详细列出windows蓝牙通信的所有功能。并且中文注释其功能,看此文档即可知道windows蓝牙通信API的开发流程,在自己的项目中使用想要的接口即可
代码片段和文件信息
#include “StdAfx.h“
#include “BlueTooth.h“
CBlueTooth::CBlueTooth(void)
{
m_Ary_RemoteBthDevInfo.SetSize ( 0 10*sizeof(BLUETOOTH_DEVICE_INFO) );
m_Ary_LocalRadioInfo.SetSize ( 0 10*sizeof(t_LocalRadioInfo) );
}
CBlueTooth::~CBlueTooth(void)
{
RemoveAll_RemoteBthDevInfo ();
RemoveAllLocalRadio ();
}
//
// 用 Socket 函数搜索附近的蓝牙设备,成功时返回设备数,否则返回-1
//
int CBlueTooth::WSAScanNearbyBthDev ()
{
m_Ary_RemoteBthDevInfo.RemoveAll ();
WSAQUERYSET wsaq;
HANDLE hLookup;
union
{
CHAR buf[5000];
double __unused; // ensure proper alignment
};
LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf;
DWORD dwSize = sizeof(buf);
BOOL bHaveName;
ZeroMemory(&wsaq sizeof(wsaq));
wsaq.dwSize = sizeof(wsaq);
wsaq.dwNameSpace = NS_BTH;
wsaq.lpcsaBuffer = NULL;
if (ERROR_SUCCESS != WSALookupServiceBegin (&wsaq LUP_CONTAINERS &hLookup))
{
TRACE ( _T(“WSALookupServiceBegin failed\n“) );
return -1;
}
ZeroMemory(pwsaResults sizeof(WSAQUERYSET));
pwsaResults->dwSize = sizeof(WSAQUERYSET);
pwsaResults->dwNameSpace = NS_BTH;
pwsaResults->lpBlob = NULL;
while (ERROR_SUCCESS == WSALookupServiceNext (hLookup LUP_RETURN_NAME | LUP_RETURN_ADDR &dwSize pwsaResults))
{
ASSERT (pwsaResults->dwNumberOfCsAddrs == 1);
BTH_ADDR b = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;
bHaveName = pwsaResults->lpszServiceInstanceName && *(pwsaResults->lpszServiceInstanceName);
t_RemoteBthDevInfo RemoteBthDevInfo;
if ( bHaveName )
{
StringCchPrintf ( RemoteBthDevInfo.szName sizeof(RemoteBthDevInfo.szName) _T(“%s“)
pwsaResults->lpszServiceInstanceName );
}
RemoteBthDevInfo.Address.ullLong = b;
TRACE (L“%s ( %04x%08x )\n“ RemoteBthDevInfo.szName GET_NAP(b) GET_SAP(b) );
m_Ary_RemoteBthDevInfo.Add ( RemoteBthDevInfo );
}
WSALookupServiceEnd(hLookup);
return (int)m_Ary_RemoteBthDevInfo.GetSize();
}
BOOL AUTHENTICATION_CALLBACK (LPVOID pvParam PBLUETOOTH_DEVICE_INFO pDevice)
{
t_AUTHENTICATION_CALLBACK_Para *pAUTHENTICATION_CALLBACK_Para = (t_AUTHENTICATION_CALLBACK_Para*)pvParam;
if ( pAUTHENTICATION_CALLBACK_Para )
{
pDevice->fAuthenticated = TRUE;
DWORD result = BluetoothUpdateDeviceRecord ( pDevice );
ASSERT ( result == ERROR_SUCCESS );
result = BluetoothSendAuthenticationResponse ( pAUTHENTICATION_CALLBACK_Para->hRadio pDevice AUTHENTICATION_PASSKEY );
if ( result == ERROR_SUCCESS )
return TRUE;
}
return FALSE;
}
//
// 用蓝牙 APIs 搜索附近的蓝牙设备,成功时返回设备数,否则返回-1
//
int CBlueTooth::ScanNearbyBthDev (
HANDLE hRadio
BOOL fReturnAuthenticated/* = TRUE*/
BOOL fReturnRemembered/* = TRUE*/
BOOL fReturnUnknown/* = TRUE*/
BOOL fReturnConnected/* = TRUE*/
BOOL fIssueInquiry/* = FALSE*/
UCHAR cTimeoutMultiplier/* = 30*/
)
{
RemoveAll_RemoteBthDevInfo ();
CWaitCursor WaitCursor;
BLUETOOTH_DEVICE_INFO bdi = { sizeof(BLUETOOTH_DEVICE_INFO) };
BLUETOOTH_DEVICE_SEARCH_PARAMS
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12846 2007-08-05 18:35 BlueTooth.cpp
文件 19019 2019-01-22 14:27 Bluetooth.docx
文件 3917 2019-01-17 09:45 BlueTooth.h
相关资源
- sublime text 3 的 ctags.exe ctags的windows命令
- windows 二维码识别技术
- Flex And Bison For Windows
- xp组策略开启了用户配置→系统→只运
- adb1.0.31windows版本
- WINDOWS下CH372/CH375的调试工具程序
- windows常用api函数
- 安卓蓝牙通信
- myeclipse-pro-2014-GA-offline-installer-window
- Windows安装kerberos
- 解决windows系统下CDCDATA Replication账户被
- WindowsSDK10.0.14393安装包
- 自己写的轻量级清理内存工具
- zabbix windows主动监控模板
- Linux下的bc计算器移植到windows下
- winutils.exe + hadoop.dll
- windows下强制删除超大量文件的方法
- 2015年 LabWindows CVI 3D graph控件编程
- slickedit pro 2017 (v22) 全功能完整版本
- visual studio express 2012 for windows desktop带
- windows下使用qt获取U盘并格式化U盘
- windows上端口转发工具
- telnet 客户端 windows下可用
- Windows Ctags.exe
- CRF++0.58 windows 二进制版
- Windows软件数字签名makecert.exesigncode.
- CVI对普通USB摄像头的控制代码
- WindowsXP和2003 CDKEY更换工具
- Intel_parallel_studio_xe_2013_sp1_update3_for_
- json 展示工具,windows系统可以打开
评论
共有 条评论