1

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

  • In UMDF you can freely call any WinRT API as it is just a COM API. Or you can use any thrid party that incapsulates all the functions and provides simple access to the BLE features. – Mike Petrichenko Apr 05 '22 at 16:54
  • Hi @MikePetrichenko, Thank you for your answer. I think I miss something. I have a umdf2 template project. Do I need to configure someting specific in the parameter project ? Thanks a lot again – EmbeddedDev Apr 06 '22 at 07:24
  • Nom you do not need something special. As I wrote WinRT API is a simple COM API. So you can call any WinRT API from your UMDF driver without any problem. (UMDF is also COM based, just FYI). – Mike Petrichenko Apr 06 '22 at 07:32
  • Thank you @MikePetrichenko. I'm new to driver development and i'm a little bit lost using theses technologies. I made new tests with umdf2 template but i'm not able to create BluetoothLEDevice... I add simple c++ source code to main thread. What do I miss ? Thank you a lot for your help. – EmbeddedDev Apr 06 '22 at 10:17
  • You should read something about WinRT usage in desktop applications first. Or, as I wrote early, you can simple use any third party libraries that incapsulates all the things. For C++ you can try Bluetooth Framework. – Mike Petrichenko Apr 06 '22 at 11:18

1 Answers1

0

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();
}
  • Hi Prasanna K, Thank you for your feedback. I found one usefull project on Github that helped me to implement ble into my driver. I add the link inside my first post. – EmbeddedDev Apr 08 '22 at 07:15