See the code below (using the Toshiba bluetooth stack):
First, start the discovery. After discovery starts attempt to stop discovery.
The code below captures the error and makes it invisible to the user. The discovery appears to work if you try again after termination, so the effect appears minimal (but annoying).
// terminate the discovery
void __fastcall TMTSBTTool::StopFindBtnClick(TObject *Sender)
{
int Rc;
if (wclBluetoothDiscovery->Active)
{
try
{
LstBx->Items->Insert(0,"Requesting terminate of discovery");
Rc = wclBluetoothDiscovery->Terminate();
LstBx->Items->Insert(0,"Termination Complete with return code = "+String(Rc));
if (Rc!=WCL_E_SUCCESS)
wclShowError(Rc);
}
catch(...)
{
// dont do anything since it seems to be a bug that doesn't have an effect
}
}
else
LstBx->Items->Insert(0,"Terminate requested, but discovery is not active.");