资源简介

本程序有扫描本地蓝牙和远程蓝牙设备、并向远程蓝牙设备发送配对请求的功能,vs2008运行成功

资源截图

代码片段和文件信息

#include “StdAfx.h“
#include 
#include “BlueTooth.h“

#pragma comment(lib“Irprops.lib“)

CBlueTooth::CBlueTooth()
{    
}

CBlueTooth::~CBlueTooth()
{
    RemoveAllLocalDev();
RemoveAllRemoteDev();
}

/******************************************************************************\
用 Socket 函数搜索附近的蓝牙设备,成功时返回设备数,否则返回-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();
}

//
// 用蓝牙 APIs 搜索附近的蓝牙设备,成功时返回设备数,否则返回-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();
}

//
// 用向导手工搜索附近的蓝牙设备并建立连接,得到设备的详细信息,成功时返回设备数
//
int CBlueTooth::ScanWithWnd(HWND hwndParent
                            HANDL

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       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.embed.manifest

     文件       1260  2018-11-07 10:50  BlueToothTest\BlueToothTest\Debug\BlueToothTest.exe.embed.manifest.res

     文件       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个文件信息

评论

共有 条评论