我使用VS2019开发了一个UMDF2.0驱动程序。在这个驱动程序中,我需要与BLE设备通信。我必须使用BluetoothLEDevice类来完成这个任务。这是一个WinRT Api。我完全不知道如何从我的司机调用C++/WinRT。有人经历过这种情况吗?
感谢你的大力支持,
编辑1
我在umdf2示例项目中使用了新cpp文件中的以下简单测试代码:
#include <windows.devices.h>
#include <windows.devices.bluetooth.h>
#include <windows.devices.bluetooth.genericattributeprofile.h>
using namespace ABI::Windows::Devices::Bluetooth;
void testBle()
{
BluetoothLEDevice dev;
}我有以下错误:
Error C2079 'dev‘使用一个未定义的C2079类
编辑2
我在GitHub上找到了一个有用的项目,它帮助我完成了所有这些工作。请查找以下链接:
https://github.com/bucienator/ble-win-cpp
再次感谢你的帮助
发布于 2022-04-08 01:24:36
您不能用默认构造函数实例化BluetoothLEDevice,因为在这种情况下没有这样的构造函数。
请使用此代码片段实例化BT设备。
#include <winrt/windows.devices.h>
#include <winrt/Windows.Devices.Bluetooth.h>
using namespace Windows::Devices::Bluetooth;
void testBle()
{
BluetoothLEDevice btDev = NULL;
IAsyncOperation<BluetoothLEDevice> launchOp =
BluetoothLEDevice::FromIdAsync(L"test");
btDev = launchOp.GetResults();
}https://stackoverflow.com/questions/71755016
复制相似问题