BlueTooth_WM.h
上传用户:hbzxgg2
上传日期:2009-03-28
资源大小:291k
文件大小:3k
- #pragma once
- #include <initguid.h>
- #include <ws2bth.h>
- #include <bthapi.h>
- #include <bthutil.h>
- #include <winsock2.h>
- /****************************************************************************************************************
- 投稿说明:
- ****************************************************************************************************************/
- #define NOTE_BlueTooth_WM
- L" ◆◆◆ 《如何在 Windows Mobile (WinCE 5.0) 中用Vc++编程查找并连接周围的蓝牙(Bluetooth)设备》◆◆◆rn
- 如何在手机中编程实现蓝牙通信即是本文将要阐述的内容,本文以Windows Mobile 5.0 为开发平台,简单介绍用蓝
- 牙APIs进行编程的要点,并附上一个源代码供大家参考。rn
- 你可以任意修改复制本代码,但请保留这段文字不要修改。rn
- 希望我能为中国的软件行业尽一份薄力!rn
- rn
- ◆◆◆ 作者 ◆◆◆rn
- 谢红伟 · chrys · chrys@163.com · http://www.howa.com.cnrn
- rn
- ◆◆◆ 日期 ◆◆◆rn
- 2007-08-18 23:31:18"
- // 配对时用得PIN码
- #define AUTHENTICATION_PASSKEY _T("0000")
- // 心电仪蓝牙名称
- #define RDS_BLUETOOTH_DEVICE_NAME _T("CONTRON")
- // 远程蓝牙设备详细信息
- typedef struct _RemoteBthDevInfo
- {
- _RemoteBthDevInfo ()
- {
- memset ( szName, 0, sizeof(szName) );
- memset ( &RemoteAddr, 0, sizeof(BT_ADDR) );
- memset ( &LocalAddr, 0, sizeof(BT_ADDR) );
- }
- TCHAR szName[64];
- BT_ADDR RemoteAddr;
- BT_ADDR LocalAddr;
- } t_RemoteBthDevInfo;
- typedef CArray<t_RemoteBthDevInfo,t_RemoteBthDevInfo&> t_Ary_RemoteBthDevInfo;
- //----------------------------------------------------------------------------------------------------
- // 一些在 bluetoothapis.h 或 bthsdpdef.h 中定义这里重新定义,因为不能包含这些 Windows 头文件
- //----------------------------------------------------------------------------------------------------
- typedef struct _BLUETOOTH_ADDRESS {
- union {
- BT_ADDR ullLong; // easier to compare again BLUETOOTH_NULL_ADDRESS
- BYTE rgBytes[ 6 ]; // easier to format when broken out
- };
- } BLUETOOTH_ADDRESS_STRUCT;
- #define BLUETOOTH_ADDRESS BLUETOOTH_ADDRESS_STRUCT
- class CBlueTooth_WM
- {
- public:
- CBlueTooth_WM(void);
- ~CBlueTooth_WM(void);
- BOOL Init ( LPCTSTR lpszCurDir );
- int ScanNearbyBthDev_Direct ();
- CString FormatBthAddress(BT_ADDR BthAddress);
- void ThreadProc_ScanNearbyBthDev ();
- BOOL ScanNearbyBthDev ( HANDLE hEvt_Notify=NULL, HWND hWnd_Noify=NULL);
- BOOL Save_RemoteBthDevInfo_ToFile(LPCTSTR lpszPath);
- BOOL Read_RemoteBthDevInfo_FromFile(LPCTSTR lpszPath);
- int ConnectToBlueToothServer ( BT_ADDR ServerAddress, LPCTSTR lpszServiceGUID );
- BOOL IsConnect () { return ( m_socketClient!=INVALID_SOCKET ); }
- void Disconnect ();
- int Transmite ( LPVOID lpData, int nSize, BOOL bSend );
- int Send ( LPVOID lpData, int nSize );
- int Recv ( LPVOID lpData, int nSize );
- int Find_RemoteBthDevInfo ( LPCTSTR lpszName_Found, t_RemoteBthDevInfo *pRemoteBthDevInfo=NULL );
- int Find_RemoteBthDevInfo ( BT_ADDR Addr_Found, t_RemoteBthDevInfo *pRemoteBthDevInfo=NULL );
- private:
- void RemoveAll_RemoteBthDevInfo(void);
- int ScanNearbyBthDevFinished ( int nRetValue );
- BOOL StringToGUID ( LPCTSTR lpszGUID, GUID *pGUID);
- BOOL Add_RemoteBthDevInfo ( t_RemoteBthDevInfo &RemoteBthDevInfo );
- public:
- t_Ary_RemoteBthDevInfo m_Ary_RemoteBthDevInfo;
- private:
- HANDLE m_hEvtEndModule;
- CString m_csCurDir;
- SOCKET m_socketClient;
- HANDLE m_hEvt_Notify_ScanNearbyBthDev;
- HWND m_hWnd_Noify_ScanNearbyBthDev;
- DWORD m_dwThreadID_ScanNearbyBthDev;
- HANDLE m_hThread_ScanNearbyBthDev;
- };