Answered by:
BluetoothLEAdvertisementWatcher for Win32 in C/C++?

Question
-
Hi. I'm using BluetoothLEAdvertisementWatcher in C# to receive advertisement packets from Bluetooth Low Energy (BLE) devices and it works good.
However I'd like to do the same in C/C++ (not .NET). What are the available APIs I can use to get the same functionality?
Wednesday, May 18, 2016 1:32 PM
Answers
-
Hi,
The same APIs are available in C and C++ as well, using COM/WRL. Here is a MSDN article that describes how to use WRL to call WinRT APIs natively: https://msdn.microsoft.com/en-us/library/hh438466.aspx.
Our APIs can be included via the following headers:
- Windows.Devices.Bluetooth.h
- Windows.Devices.Bluetooth.Advertisement.h
These headers are shipped as part of the Windows SDK.
This posting is provided AS IS with no warranties, and confers no rights.
- Proposed as answer by Matthew Beaver [MSFT]Microsoft employee Friday, May 27, 2016 4:51 PM
- Marked as answer by EmilenL Friday, May 27, 2016 10:11 PM
Thursday, May 26, 2016 12:28 AM
All replies
-
Hi,
The same APIs are available in C and C++ as well, using COM/WRL. Here is a MSDN article that describes how to use WRL to call WinRT APIs natively: https://msdn.microsoft.com/en-us/library/hh438466.aspx.
Our APIs can be included via the following headers:
- Windows.Devices.Bluetooth.h
- Windows.Devices.Bluetooth.Advertisement.h
These headers are shipped as part of the Windows SDK.
This posting is provided AS IS with no warranties, and confers no rights.
- Proposed as answer by Matthew Beaver [MSFT]Microsoft employee Friday, May 27, 2016 4:51 PM
- Marked as answer by EmilenL Friday, May 27, 2016 10:11 PM
Thursday, May 26, 2016 12:28 AM -
Thanks for your answer.
I see one problem however. The advertisement report does contain the bd addr of the device, but not the bd addr type (public / random) which is needed to uniquely identify the device according to the bluetooth standard. That bit is sent over the air so it should be possible to forward it to the app.
Tuesday, May 31, 2016 1:04 PM -
The same APIs are available in C and C++ as well, using COM/WRL. Here is a MSDN article that describes how to use WRL to call WinRT APIs natively:
Our APIs can be included via the following headers:
- Windows.Devices.Bluetooth.h
- Windows.Devices.Bluetooth.Advertisement.h
These headers are shipped as part of the Windows SDK.
I am compiling under VC 17 ( community edition ) for Win64 platform and when I include these headers I get errors
#include <windows.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include "Windows.Devices.Bluetooth.h"
#include "Windows.Devices.Bluetooth.Advertisement.h"
c:\program files (x86)\windows kits\10\include\10.0.16299.0\winrt\Windows.UI.ViewManagement.h(1609): error C3837: attributes are not allowed in this contextc:\program files (x86)\windows kits\10\include\10.0.16299.0\winrt\Windows.Devices.Sms.h(2751): error C3837: attributes are not allowed in this context
c:\program files (x86)\windows kits\10\include\10.0.16299.0\winrt\Windows.Media.Playback.h(4629): error C3837: attributes are not allowed in this contextc:\program files (x86)\windows kits\10\include\10.0.16299.0\winrt\Windows.Media.Devices.h(3711): error C3837: attributes are not allowed in this contextIs there a special macro that needs defining or a compiler flag than needs ot be set or some other correction needed ?
- Edited by Peter Kennard Tuesday, December 12, 2017 12:18 AM erronoeous line
Tuesday, December 12, 2017 12:17 AM -
I face the same issue.
What is the fix for this?
- Edited by tejas_s Wednesday, February 6, 2019 1:48 PM
Wednesday, February 6, 2019 1:48 PM