How to all C++/WinRT from UMDF2

371 views Asked by At

I develop an UMDF2.0 driver using VS2019. Inside this driver I need to communicate with an BLE device. I have to use BluetoothLEDevice class to do this. This is a WinRT Api. I'm completely lost on how to call C++/WinRT from my driver. Does anyone have experienced this situation ?

Thank a lot for your great support,

EDIT 1#

I use the following simple test code in new cpp file into umdf2 sample project:

#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;

}

I have the following error :

Error C2079 'dev' uses a class of 'ABI::Windows::Devices::Bluetooth::BluetoothLEDevice' not defined

EDIT 2

I found one usefull project on GitHub that help me a lot to make all this work. Please find the link below :

https://github.com/bucienator/ble-win-cpp

Thank you again for your help

1

There are 1 answers

1
Prasanna K On

You cannot instantiate the BluetoothLEDevice with default constructor because there is no such constructor in this case.

Please use this code snippet in instantiate the BT device.

#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();
}