MFC BlueTooth 통신 샘플 Network Control

Windows SDK 6.1 이상부터 지원함

Socket 으로 BlueTooth 장치를 사용함..

MS의 Bluetooth 관련 reference site
중요 structure와 function 사용법이 나와 있음...

Bluetooth를 검색해서 간단한 정보를 표시해 주는 예제

  • #include <windows.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <winsock2.h>
  • #include <bthdef.h>
  • #include <BluetoothAPIs.h>

  • #pragma comment(lib, "Irprops.lib")

  • BLUETOOTH_FIND_RADIO_PARAMS m_bt_find_radio = {
  • sizeof(BLUETOOTH_FIND_RADIO_PARAMS)
  • };

  • BLUETOOTH_RADIO_INFO m_bt_info = {
  • sizeof(BLUETOOTH_RADIO_INFO),
  • 0,
  • };

  • BLUETOOTH_DEVICE_SEARCH_PARAMS m_search_params = {
  • sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),
  • 1,
  • 0,
  • 1,
  • 1,
  • 1,
  • 15,
  • NULL
  • };

  • BLUETOOTH_DEVICE_INFO m_device_info = {
  • sizeof(BLUETOOTH_DEVICE_INFO),
  • 0,
  • };

  • HANDLE m_radio = NULL;
  • HBLUETOOTH_RADIO_FIND m_bt = NULL;
  • HBLUETOOTH_DEVICE_FIND m_bt_dev = NULL;
  • int DiscoveryBlueToothDevices(CString &BTMac, BOOL &isBTSuccess)
  • {
  • while(true) {
  • m_bt = BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);

  • int m_radio_id = 0;
  • do {
  • m_radio_id++;

  • BluetoothGetRadioInfo(m_radio, &m_bt_info);

  • dprintf(L"Radio %d:\r\n", m_radio_id);
  • dprintf(L"\tName: %s\r\n", m_bt_info.szName);
  • dprintf(L"\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_bt_info.address.rgBytes[1], m_bt_info.address.rgBytes[0], m_bt_info.address.rgBytes[2], m_bt_info.address.rgBytes[3], m_bt_info.address.rgBytes[4], m_bt_info.address.rgBytes[5]);
  • dprintf(L"\tClass: 0x%08x\r\n", m_bt_info.ulClassofDevice);
  • dprintf(L"\tManufacturer: 0x%04x\r\n", m_bt_info.manufacturer);

  • m_search_params.hRadio = m_radio;

  • ::ZeroMemory(&m_device_info, sizeof(BLUETOOTH_DEVICE_INFO));
  • m_device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);

  • m_bt_dev = BluetoothFindFirstDevice(&m_search_params, &m_device_info);

  • int m_device_id = 0;
  • do {
  • m_device_id++;

  • dprintf(L"\tDevice %d:\r\n", m_device_id);
  • dprintf(L"\t\tName: %s\r\n", m_device_info.szName);
  • dprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
  • dprintf(L"\t\tClass: 0x%08x\r\n", m_device_info.ulClassofDevice);
  • dprintf(L"\t\tConnected: %s\r\n", m_device_info.fConnected ? L"true" : L"false");
  • dprintf(L"\t\tAuthenticated: %s\r\n", m_device_info.fAuthenticated ? L"true" : L"false");
  • dprintf(L"\t\tRemembered: %s\r\n", m_device_info.fRemembered ? L"true" : L"false");

  • if ( wcslen(m_device_info.szName) > 0 )
  • {
  • isBTSuccess = true;
  • break;
  • }

  • } while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));

  • BluetoothFindDeviceClose(m_bt_dev);
  • } while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));

  • BluetoothFindRadioClose(m_bt);

  • Sleep(10000);
  • break;
  • }

  • return 0;
  • }

또 다른 예제...



덧글

댓글 입력 영역


통계 위젯 (블랙)

00
5
430644