資源簡(jiǎn)介
本程序有掃描本地藍(lán)牙和遠(yuǎn)程藍(lán)牙設(shè)備、并向遠(yuǎn)程藍(lán)牙設(shè)備發(fā)送配對(duì)請(qǐng)求的功能,vs2008運(yùn)行成功
代碼片段和文件信息
#include?“StdAfx.h“
#include?
#include?“BlueTooth.h“
#pragma?comment(lib“Irprops.lib“)
CBlueTooth::CBlueTooth()
{????
}
CBlueTooth::~CBlueTooth()
{
????RemoveAllLocalDev();
RemoveAllRemoteDev();
}
/******************************************************************************\
用?Socket?函數(shù)搜索附近的藍(lán)牙設(shè)備,成功時(shí)返回設(shè)備數(shù),否則返回-1
\******************************************************************************/
int?CBlueTooth::ScanBySocket()
{
RemoveAllRemoteDev();
WSAQUERYSET?wsaq;
HANDLE??????hLookup?=???NULL;
union
{
CHAR?buf[5000];
double?__unused;?//?ensure?proper?alignment
};
LPWSAQUERYSET?pwsaResults?=?(LPWSAQUERYSET)?buf;
DWORD?dwSize?=?sizeof(buf);
????memset(&wsaq0sizeof(wsaq));
wsaq.dwSize?=?sizeof(wsaq);
wsaq.dwNameSpace?=?NS_BTH;
wsaq.lpcsaBuffer?=?NULL;
if?(ERROR_SUCCESS?!=?WSALookupServiceBegin?(&wsaq?LUP_CONTAINERS?&hLookup))
{
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);
RemoteDev?dev;
dev.Address?=???((SOCKADDR_BTH?*)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;
????????dev.sName???=???pwsaResults->lpszServiceInstanceName;
m_arrRemote.Add(dev);
}
WSALookupServiceEnd(hLookup);
return?(int)m_arrRemote.GetSize();
}
//
//?用藍(lán)牙?APIs?搜索附近的藍(lán)牙設(shè)備,成功時(shí)返回設(shè)備數(shù),否則返回-1
//
int?CBlueTooth::Scan(HANDLE?hRadioBOOL?fReturnAuthenticatedBOOL?fReturnRememberedBOOL?fReturnUnknown
????????????????????BOOL?fReturnConnectedBOOL?fIssueInquiryUCHAR?cTimeoutMultiplier)
{
RemoveAllRemoteDev();
BLUETOOTH_DEVICE_INFO???????????bdi?=???{?sizeof(BLUETOOTH_DEVICE_INFO)?};
BLUETOOTH_DEVICE_SEARCH_PARAMS??bdsp;
ZeroMemory(&bdsp?sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS));
bdsp.dwSize?????????????????=???sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
bdsp.hRadio?????????????????=???hRadio;
bdsp.fReturnAuthenticated???=???fReturnAuthenticated;
bdsp.fReturnRemembered??????=???fReturnRemembered;
bdsp.fReturnUnknown?????????=???fReturnUnknown;
bdsp.fReturnConnected???????=???fReturnConnected;
bdsp.fIssueInquiry??????????=???fIssueInquiry;
bdsp.cTimeoutMultiplier?????=???cTimeoutMultiplier;
????HBLUETOOTH_DEVICE_FIND??hbf?=???BluetoothFindFirstDevice(&bdsp?&bdi);
if(hbf?==?NULL)
????{
????????return?-1;
????}
do
{
TRACE?(?_T(“%s?(?%s?)\n“)?bdi.szName?AddrToStr(bdi.Address.rgBytes)?);
RemoteDev?dev;
dev.Address?=???bdi.Address.ullLong;
????????dev.sName???=???bdi.szName;
m_arrRemote.Add(dev);
????}while(BluetoothFindNextDevice(hbf&bdi));
BluetoothFindDeviceClose(hbf);
return?m_arrRemote.GetSize();
}
//
//?用向?qū)止に阉鞲浇乃{(lán)牙設(shè)備并建立連接,得到設(shè)備的詳細(xì)信息,成功時(shí)返回設(shè)備數(shù)
//
int?CBlueTooth::ScanWithWnd(HWND hwndParent
????????????????????????????HANDL
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????8331??2018-11-08?16:19??BlueToothTest\BlueToothTest\BlueTooth.cpp
?????文件???????3205??2018-11-08?16:04??BlueToothTest\BlueToothTest\BlueTooth.h
?????文件??????91164??2018-11-13?09:43??BlueToothTest\BlueToothTest\BlueToothTest.aps
?????文件???????1744??2018-11-07?10:49??BlueToothTest\BlueToothTest\BlueToothTest.cpp
?????文件????????487??2018-11-07?10:49??BlueToothTest\BlueToothTest\BlueToothTest.h
?????文件???????6595??2018-11-08?16:27??BlueToothTest\BlueToothTest\BlueToothTest.rc
?????文件???????6026??2018-11-08?09:01??BlueToothTest\BlueToothTest\BlueToothTest.vcproj
?????文件???????1427??2018-11-13?09:44??BlueToothTest\BlueToothTest\BlueToothTest.vcproj.MQKZDKMJPSXNYL5.Administrator.user
?????文件??????11108??2018-11-13?09:44??BlueToothTest\BlueToothTest\BlueToothTestDlg.cpp
?????文件???????1002??2018-11-13?09:44??BlueToothTest\BlueToothTest\BlueToothTestDlg.h
?????文件??????81477??2018-11-08?16:21??BlueToothTest\BlueToothTest\Debug\BlueTooth.obj
?????文件???????1196??2018-11-07?10:50??BlueToothTest\BlueToothTest\Debug\BlueToothTest.exe.em
?????文件???????1260??2018-11-07?10:50??BlueToothTest\BlueToothTest\Debug\BlueToothTest.exe.em
?????文件???????1120??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\BlueToothTest.exe.intermediate.manifest
?????文件??????28848??2018-11-08?16:28??BlueToothTest\BlueToothTest\Debug\BlueToothTest.obj
?????文件???44302336??2018-11-07?16:08??BlueToothTest\BlueToothTest\Debug\BlueToothTest.pch
?????文件??????70716??2018-11-08?16:42??BlueToothTest\BlueToothTest\Debug\BlueToothTest.res
?????文件??????79938??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\BlueToothTestDlg.obj
?????文件???????6778??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\BuildLog.htm
?????文件??????24453??2018-11-08?16:05??BlueToothTest\BlueToothTest\Debug\DlgPairSend.obj
?????文件??????28005??2018-11-08?16:05??BlueToothTest\BlueToothTest\Debug\GGBlueTooth.obj
?????文件?????????65??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\mt.dep
?????文件?????630896??2018-11-07?16:08??BlueToothTest\BlueToothTest\Debug\stdafx.obj
?????文件????2018304??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\vc90.idb
?????文件????3657728??2018-11-08?17:14??BlueToothTest\BlueToothTest\Debug\vc90.pdb
?????文件???????1008??2018-11-07?16:35??BlueToothTest\BlueToothTest\DlgPairSend.cpp
?????文件????????769??2018-11-07?17:32??BlueToothTest\BlueToothTest\DlgPairSend.h
?????文件????????423??2018-11-07?16:06??BlueToothTest\BlueToothTest\DlgPairSend.htm
?????文件???????7186??2018-11-08?15:53??BlueToothTest\BlueToothTest\GGBlueTooth.cpp
?????文件???????2054??2018-11-08?09:00??BlueToothTest\BlueToothTest\GGBlueTooth.h
............此處省略38個(gè)文件信息
評(píng)論
共有 條評(píng)論