@pmr:看下面的代码
@singeroftheall:我对这两件事都有问题。插入和搜索。我认为搜索部分已经完成。现在如何在向量中插入我的 mac 地址?我的地址保存在变量 m_device_info.Adress.rgBytes[]; 见下文。
wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
可以混合使用 C 和 C++ 语言吗?因为向量输出是在 c++ 中?
==================================================== ================================ 我写了一个代码,它显示了所有可用的蓝牙设备。我只想wchar
将可用设备的所有 MAC 地址(类型:)保存在向量列表中。之后我想搜索一个指定的wchar
,如果它在向量列表中。
我不是 c/c++ 的专业程序员,只需要这个来比较东西进行演示,看看我的想法是否有效。如果有人可以帮助我,我会非常高兴和高兴。我还搜索了谷歌并写了其他常见问题解答,但没有找到对我有帮助的好的解决方案。
搜索设备的代码:
#include "stdafx.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <bthdef.h>
#include <BluetoothAPIs.h>
#include <iostream>
#include <vector>
using namespace std;
#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 wmain(int argc, wchar_t **args) {
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);
wprintf(L"Radio %d:\r\n", m_radio_id);
wprintf(L"\tName: %s\r\n", m_bt_info.szName);
wprintf(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]);
wprintf(L"\tClass: 0x%08x\r\n", m_bt_info.ulClassofDevice);
wprintf(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);
vector <string> macadresse;
int n;
int m_device_id = 0;
do {
m_device_id++;
wprintf(L"\tDevice %d:\r\n", m_device_id);
wprintf(L"\t\tName: %s\r\n", m_device_info.szName);
wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
wprintf(L"\t\tClass: 0x%08x\r\n", m_device_info.ulClassofDevice);
//devicemc[m_device_id]= m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5];
//macadresse.push_back(string (&m_device_info.Address.rgBytes[0], &m_device_info.Address.rgBytes[1], &m_device_info.Address.rgBytes[2], &m_device_info.Address.rgBytes[3], &m_device_info.Address.rgBytes[4], &m_device_info.Address.rgBytes[5]));
} 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);
}
return 0;
}