?? bluetooth.h
字號:
#pragma once
/*
藍牙封裝類
注意:
1、在InitInstance()函數中調用 WSADATA wsd; WSAStartup (MAKEWORD(2,2), &wsd);
*/
/****************************************************************************************************************
投稿說明:
****************************************************************************************************************/
#define NOTE_Bluetooth \
_T(" ◆◆◆ 《藍牙(Bluetooth)設備查找、藍牙服務發現啟動、藍牙虛擬串口通信》◆◆◆\r\n\
利用藍牙 APIs 編寫的多種方式進行藍牙設備查找、服務發現啟動,藍牙虛擬串口的通信,支持16進制和字符串兩種方式。\r\n\
你可以任意修改復制本代碼,但請保留這段文字不要修改。\r\n\
希望我能為中國的軟件行業盡一份薄力!\r\n\
\r\n\
◆◆◆ 作者 ◆◆◆\r\n\
謝紅偉 · chrys · chrys@163.com · http://www.howa.com.cn\r\n\
\r\n\
◆◆◆ 日期 ◆◆◆\r\n\
2007-08-07 00:32:53\r\n")
#include "PublicFunc.h"
// for WSALookupServiceBegin() WSALookupServiceNext etc.
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#include <ws2bth.h>
// for BluetoothFindFirstDevice() BluetoothFindNextDevice() etc.
#include <bthsdpdef.h>
#include <BluetoothAPIs.h>
#pragma comment ( lib, "Irprops.lib")
// 配對時用得PIN碼
#define AUTHENTICATION_PASSKEY _T("0000")
// 配對回調函數的參數
typedef struct _AUTHENTICATION_CALLBACK_Para
{
LPVOID lpBlueTooth;
HANDLE hRadio;
} t_AUTHENTICATION_CALLBACK_Para;
// 遠程藍牙設備詳細信息
typedef struct _RemoteBthDevInfo
{
_RemoteBthDevInfo ()
{
hRadio = NULL;
memset ( szName, 0, sizeof(szName) );
memset ( &Address, 0, sizeof(BLUETOOTH_ADDRESS) );
memset ( guidServices, 0, sizeof(guidServices) );
hRegHandle = NULL;
pAUTHENTICATION_CALLBACK_Para = NULL;
}
HANDLE hRadio;
TCHAR szName[64];
BLUETOOTH_ADDRESS Address;
GUID guidServices[10];
HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle;
t_AUTHENTICATION_CALLBACK_Para *pAUTHENTICATION_CALLBACK_Para;
} t_RemoteBthDevInfo;
typedef CArray<t_RemoteBthDevInfo,t_RemoteBthDevInfo&> t_Ary_RemoteBthDevInfo;
// 本地藍牙設備信息
typedef struct _LocalRadioInfo
{
_LocalRadioInfo()
{
memset ( &RadioInfo, 0, sizeof(BLUETOOTH_RADIO_INFO) );
RadioInfo.dwSize = sizeof(BLUETOOTH_RADIO_INFO);
hRadio = NULL;
}
BLUETOOTH_RADIO_INFO RadioInfo;
HANDLE hRadio;
} t_LocalRadioInfo;
typedef CArray<t_LocalRadioInfo,t_LocalRadioInfo&> t_Ary_LocalRadioInfo;
class CBlueTooth
{
public:
CBlueTooth(void);
~CBlueTooth(void);
int WSAScanNearbyBthDev ();
int ScanNearbyBthDev (
HANDLE hRadio,
BOOL fReturnAuthenticated = TRUE,
BOOL fReturnRemembered = TRUE,
BOOL fReturnUnknown = TRUE,
BOOL fReturnConnected = TRUE,
BOOL fIssueInquiry = FALSE,
UCHAR cTimeoutMultiplier = 30
);
BOOL ShowPropertySheet(int nIndex, HWND hwdParent=NULL);
BOOL RequestAuthenticateDevice(int nIndex, HWND hwdParent=NULL, DWORD *presult=NULL);
CString FormatBthAddress(BYTE *BthAddress);
int EnumerateLocalRadios(void);
int ScanNearbyBthDev_Wizard (
HWND hwndParent,
HANDLE hRadio,
LPWSTR pszInfo=NULL,
BOOL fForceAuthentication=FALSE,
BOOL fShowAuthenticated=FALSE,
BOOL fShowRemembered=TRUE,
BOOL fShowUnknown=TRUE,
BOOL fAddNewDeviceWizard=TRUE,
BOOL fSkipServicesPage=FALSE,
PFN_DEVICE_CALLBACK pfnDeviceCallback=NULL,
LPVOID pvParam=NULL
);
BOOL BluetoothGetDeviceInfo ( IN t_RemoteBthDevInfo& RemoteBthDevInfo, OUT BLUETOOTH_DEVICE_INFO *pbtdi );
private:
void RemoveAllLocalRadio(void);
int EnumerateInstalledServices(t_RemoteBthDevInfo& RemoteBthDevInfo);
void RemoveAll_RemoteBthDevInfo(void);
BOOL BluetoothSetServiceState ( HANDLE hRadio, BLUETOOTH_DEVICE_INFO &bdi, GUID guidService, DWORD dwServiceFlags );
public:
t_Ary_RemoteBthDevInfo m_Ary_RemoteBthDevInfo;
t_Ary_LocalRadioInfo m_Ary_LocalRadioInfo;
public:
int Test(void);
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -