Hi All,

I want to trap inRange and outRange event of the bluetooth device i.e. paired with my windows7 machine.

Thanks in advance.

Dani AI

Generated

For : two practical approaches exist for “inRange” / “outRange” on Windows 7 — an event-driven method that listens for Bluetooth-specific WM_DEVICECHANGE custom events, and an active-inquiry (polling) method that performs periodic scans and diffs results. ’s clarification of the terms was correct, and ’s timer idea is a valid fallback when the event path isn’t sufficient. (learn.microsoft.com)

Event-driven (efficient): open a handle to the local radio (BluetoothFindFirstRadio or SetupDiGetClassDevs), call RegisterDeviceNotification on that handle with DBT_DEVTYP_HANDLE, then watch WM_DEVICECHANGE for DBT_CUSTOMEVENT. Cast lParam to DEV_BROADCAST_HANDLE and check dbch_eventguid for GUID_BLUETOOTH_RADIO_IN_RANGE or GUID_BLUETOOTH_RADIO_OUT_OF_RANGE; the dbch_data buffer contains a BTH_RADIO_IN_RANGE or BLUETOOTH_ADDRESS payload as documented. This sends OS-level “found” / “not found” notices without continuous polling. (learn.microsoft.com)

Active inquiry (robust fallback): force an inquiry with the Win32 Bluetooth APIs — call BluetoothFindFirstDevice / BluetoothFindNextDevice using BLUETOOTH_DEVICE_SEARCH_PARAMS with fIssueInquiry = TRUE and an appropriate cTimeoutMultiplier, collect device addresses, then compare to the previous set to emit in/out events. Example sketch (single-threaded probe; keep off the UI thread):

// minimal scan (caller must not block UI)
BLUETOOTH_DEVICE_SEARCH_PARAMS params = {};
params.dwSize = sizeof(params);
params.fReturnAuthenticated = TRUE;
params.fReturnRemembered  = TRUE;
params.fIssueInquiry      = TRUE;
params.cTimeoutMultiplier = 4; // ~5.12s

BLUETOOTH_DEVICE_INFO info = { sizeof(info) };
HBLUETOOTH_DEVICE_FIND hFind = BluetoothFindFirstDevice(&params, &info);

std::set<unsigned long long> seen;
if (hFind) {
  do { seen.insert(info.Address.ullLong); }
  while (BluetoothFindNextDevice(hFind, &info));
  BluetoothFindDeviceClose(hFind);
}
// compare `seen` with previous set to raise in/out events

The OS event path will not emit OUT_OF_RANGE for “remembered” (paired) devices, and BluetoothFindFirstDevice does not discover BLE devices (WinRT APIs are required for LE). Combine both approaches: register for device notifications and use short, infrequent scans as a fallback when events are not emitted. Avoid long/blocking work in the WM_DEVICECHANGE handler — hand work off to a worker thread. (learn.microsoft.com)

Recommended Answers

All 4 Replies

Could you explain the terms "inrange" and "outrange" ?.
What actually you want to perform after pairing the device?

inrange means that device can be searched through bluetooth and outrange that u are not able to communicate with it.

inrange means that device can be searched through bluetooth and outrange that u are not able to communicate with it.

yes u r right.

Did you just comment on your own post? :S... riiiight...

Anyway how about just creating a timer that repeats and emits a signal that will cause all bluetooth devices to be searched... and when one is returned that was not there before you emit a signal that would start the slot event for in range and the same when one isnt there that used to be?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.