KingKarl237 KingKarl237 -4 years ago 302
C++ Question

Bluetooth Low Energy Stack Overflow on Windows

I wanted to write a program that is receiving data every 10ms over Bluetooth Low Energy.

I get a lot of things to work, but I always have one problem and canĀ“t find the source.
Here is the basis of my Code written in C++Builder 10 on Windows 10.

> //---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#pragma package(smart_init)

#define Characteristic_UUID "{6e400003-b5a3-f393-e0a9-e50e24dcca9e}"
#define Service_UUID "{6e400001-b5a3-f393-e0a9-e50e24dcca9e}"
#pragma resource "*.dfm"

TForm1 *Form1;
TBluetoothLEDevice* device;
TBluetoothGattCharacteristicList* characteristic ;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
void __fastcall TForm1::BluetoothLE1EndDiscoverDevices(TObject * const Sender, TBluetoothLEDeviceList * const ADeviceList)

device = ADeviceList->First();

void __fastcall TForm1::BluetoothLE1ServicesDiscovered(TObject * const Sender, TBluetoothGattServiceList * const AServiceList)


CLSIDFromString(TEXT(Service_UUID), &AGuid);
TBluetoothGattService* service = BluetoothLE1->GetService(device,AGuid);
//TBluetoothGattServiceList* abcd = BluetoothLE1->GetServices(device);

CLSIDFromString(TEXT(Characteristic_UUID), &AGuid);
characteristic = BluetoothLE1->GetCharacteristics(service);
while(characteristic->First()->UUID != AGuid)

if(characteristic->First()!= NULL);
void __fastcall TForm1::BluetoothLE1CharacteristicRead(TObject * const Sender, TBluetoothGattCharacteristic * const ACharacteristic,
TBluetoothGattStatus AGattStatus)

static long i;

Label1->Caption = i;

After exactly 86303 Notifys (calling BluetoothLE1CharacteristicRead) I get a Stack Overflow. So there must be something wrong.
At the beginning i wrote the program in Visual Studio in C++ with the Windows Drivers Functions, but same thing.

Answer Source

I have found the problem. It is a bug in the Win32 Bluetooth APIs. With Windows Update KB3156421 every program crashes after one notification and Mircosoft gives a workaround. Link

That workaround fixes my problem above too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download