资源简介
蓝牙(Bluetooth)设备查找、蓝牙服务发现启动、蓝牙虚拟串口通信
代码片段和文件信息
#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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 888 2007-08-02 23:12 BlueToothExc.sln
..A..H. 111104 2007-08-07 01:18 BlueToothExc.suo
文件 5901 2007-08-05 17:28 BlueToothExc.vcproj
文件 1415 2007-08-07 01:18 BlueToothExc.vcproj.CHRYS-T60.chrys.user
文件 14924 2007-08-07 01:18 BlueToothExcDlg.cpp
文件 1738 2007-08-07 00:45 BlueToothExcDlg.h
文件 8889 2007-08-07 01:10 HwCOM.cpp
文件 1668 2007-08-07 01:12 HwCOM.h
文件 2700 2007-08-07 00:39 PublicFunc.cpp
文件 1277 2007-08-06 23:22 PublicFunc.h
文件 1603 2007-08-06 23:11 resource.h
文件 212 2007-08-02 23:12 stdafx.cpp
文件 2930 2007-08-05 18:36 stdafx.h
文件 12846 2007-08-05 18:35 BlueTooth.cpp
文件 3891 2007-08-07 00:36 BlueTooth.h
文件 61336 2007-08-07 00:44 BlueToothExc.aps
文件 2407 2007-08-03 22:59 BlueToothExc.cpp
文件 579 2007-08-03 22:59 BlueToothExc.h
文件 7025 2007-08-07 00:44 BlueToothExc.rc
----------- --------- ---------- ----- ----
243333 19
相关资源
- PacketMonitor.rar
- SUSE_liunx_11_SP4.txt
- UBS网测-SHL测评-逻辑题答案及详解.d
- 新浪博客wincc7.4破解.docx
- 基站批量查询系统beta.rar
- 2010破解版.rar
-
license_9.0.1_2020.xm
l - 百度提取码.txt
- EAGLE原理图和PCB转AD脚本.rar
- DbVisualizer10.0.18破解LicenseKey.zip
- 3531Asdk.txt
- 数值最优化算法与理论第二版(李董
- Visio2010简体中文专业版64位.iso镜像.
- sobel.v
- 亚普端口扫描器.zip
- 微信自助解封v3.1By小虎增加优码云码
- 36Maven视频教程百度网盘.txt
- 链接和密码.txt
- ArcGIS.txt
- atguigu-bigdata.txt
- 相册.rar
- ADC0804.rar
- pycharm-professional-2018.1.3.tar.gz
- eetop.cn_Vivado2016.1附件连接.txt
- u010836455_8673029.rar
- RSLogix5000V20授权.zip
- 学习HyperledgerFabric实战联盟链.txt
- 传智播客Ado.Net项目开发视频教程(第
- protues成功仿真AD(TLC549)采集系统.
- KongDangJieLong.sln
评论
共有 条评论