-
大小: 15.44MB文件類(lèi)型: .rar金幣: 1下載: 0 次發(fā)布日期: 2023-07-14
- 語(yǔ)言: C/C++
- 標(biāo)簽: C++藍(lán)牙??
資源簡(jiǎn)介
這個(gè)是基于C++的藍(lán)牙通信,可以實(shí)現(xiàn)電腦藍(lán)牙模塊與無(wú)線筆記本藍(lán)牙的連接并進(jìn)行通信。
代碼片段和文件信息
#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?函數(shù)搜索附近的藍(lán)牙設(shè)備,成功時(shí)返回設(shè)備數(shù),否則返回-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;
}
//
//?用藍(lán)牙?APIs?搜索附近的藍(lán)牙設(shè)備,成功時(shí)返回設(shè)備數(shù),否則返回-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?
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???????1415??2008-06-24?17:04??BlueToothExc.vcproj.CHRYS-T60.chrys.user
?????文件??????20932??2007-12-26?18:26??DlgBlueToothExc.cpp
?????文件???????2336??2007-12-26?18:25??DlgBlueToothExc.h
?????文件??????10045??2007-08-11?17:32??DlgDataShow.cpp
?????文件???????1490??2007-08-10?00:30??DlgDataShow.h
?????文件???????8889??2007-08-07?19:30??HwCOM.cpp
?????文件???????1668??2007-08-07?19:30??HwCOM.h
?????文件??????20791??2007-08-11?17:07??PublicFunc.cpp
?????文件???????4585??2007-08-11?13:14??PublicFunc.h
?????文件???????3129??2007-12-26?18:25??resource.h
?????文件???????5096??2007-08-11?15:25??StaticDataCurve.cpp
?????文件???????1453??2007-08-11?17:35??StaticDataCurve.h
?????文件????????212??2007-08-07?19:30??stdafx.cpp
?????文件???????2930??2007-08-07?19:30??stdafx.h
?????目錄??????????0??2008-06-24?17:04??Debug
?????文件?????241664??2008-06-24?17:03??Debug\BlueToothExc.exe
?????目錄??????????0??2007-08-08?11:13??res
?????文件??????21630??2007-08-07?19:30??res\BlueToothExc.ico
?????文件????????403??2007-08-07?19:30??res\BlueToothExc.rc2
?????文件??????12846??2007-08-07?19:30??BlueTooth.cpp
?????文件???????3891??2007-08-07?19:30??BlueTooth.h
?????文件???????2407??2007-08-07?19:30??BlueToothExc.cpp
?????文件????????579??2007-08-07?19:30??BlueToothExc.h
?????文件???????9700??2007-12-26?18:25??BlueToothExc.rc
?????文件????????888??2007-08-07?19:30??BlueToothExc.sln
????..A..H.?????13312??2008-06-24?17:04??BlueToothExc.suo
?????文件???????6173??2007-08-11?22:17??BlueToothExc.vcproj
?????文件??????12846??2007-08-07?19:30??BlueToothExc\BlueTooth.cpp
?????文件???????3891??2007-08-07?19:30??BlueToothExc\BlueTooth.h
?????文件???????2407??2007-08-07?19:30??BlueToothExc\BlueToothExc.cpp
............此處省略54個(gè)文件信息
評(píng)論
共有 條評(píng)論