MFC
BluetoothFindFirstDevice Example
leo21c
2024. 10. 21. 19:29
BluetoothFindFirstDevice 함수(bluetoothapis.h) - Win32 apps
BluetoothFindFirstDevice 함수는 Bluetooth 디바이스 열거를 시작합니다.
learn.microsoft.com
BluetoothFindFirstDevice 함수는 Bluetooth 디바이스 열거를 시작합니다.
HBLUETOOTH_DEVICE_FIND BluetoothFindFirstDevice(
const BLUETOOTH_DEVICE_SEARCH_PARAMS *pbtsp,
BLUETOOTH_DEVICE_INFO *pbtdi
);
API를 이용한 Sample Code
#include "bluetoothapis.h"
#pragma comment(lib, "Bthprops.lib")
void CBluetoothFindFirstDeviceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST, m_listBox);
}
void CBluetoothFindFirstDeviceDlg::OnBnClickedButton1()
{
BluetoothFind();
}
int CBluetoothFindFirstDeviceDlg::BluetoothFind()
{
HBLUETOOTH_DEVICE_FIND founded_device;
BLUETOOTH_DEVICE_INFO device_info;
memset(&device_info, 0, sizeof(BLUETOOTH_DEVICE_INFO));
device_info.dwSize = sizeof(device_info);
BLUETOOTH_DEVICE_SEARCH_PARAMS search_criteria;
memset(&search_criteria, 0, sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS));
search_criteria.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
search_criteria.fReturnAuthenticated = FALSE;
search_criteria.fReturnRemembered = FALSE;
search_criteria.fReturnConnected = TRUE;
search_criteria.fReturnUnknown = FALSE;
search_criteria.fIssueInquiry = FALSE;
search_criteria.cTimeoutMultiplier = 0;
founded_device = BluetoothFindFirstDevice(&search_criteria, &device_info);
if (founded_device == NULL)
{
TRACE(_T("(%s)[%d] Error: %d\n"), __FUNCTIONW__, __LINE__, WSAGetLastError());
return -1;
}
do
{
m_listBox.AddString(device_info.szName);
TRACE(_T("(%s)[%d] founded device : %s\n"), __FUNCTIONW__, __LINE__,device_info.szName);
} while (BluetoothFindNextDevice(founded_device, &device_info));
return 0;
}
void CBluetoothFindFirstDeviceDlg::OnBnClickedButton2()
{
m_listBox.ResetContent();
}
LIST