0

I am using 32 feet library to connect and discover Bluetooth devices. If I rename my bluetooth device name, after that if I try to discover, its giving me old name.

1)Connect to bluetooh device1. 2)Disconnect to bluetooh device1. 3)Rename bluetoothdevice1 to bluetoothdevice2. 4)If I discover now, I am getting bluetoothdevice1, I do second discover again I am getting bluetoothdevice2.

Not sure it is the issue with 32feet or windows.Is it caching somewhere in the system and it is returning it?

  • 1
    It is correct behaviour for MS drivers. In order to resolve this you have to process some WM_DEVICECHANGE message in your application (Refer to MSDN: Bluetooth and WM_DEVICECHANGE). Bluetooth sends this message to the subscribed applications when device name is resolved. In is the similar to reading empty device name issue. – Mike Petrichenko Feb 27 '19 at 21:35
  • Thanks @mike-petrichenko, I downloaded your framework for Demo and when tested with your framework it is working Perfect. I mean even though I change the name of the Bluetooth device, with your Demo application if I discover, it is giving correct blue tooth device name(i mean the new updated name). I assume your framework might be using these WM_DEVICECHANGE messages. I will try to use them and see if I can make any progress. Thanks a lot:) – Ashok Palakurthi Feb 28 '19 at 22:08
  • You are welcome. – Mike Petrichenko Mar 01 '19 at 07:27
  • @mike-petrichenko NativeMethods.DEV_BROADCAST_DEVICEINTERFACE deviceInterface = new NativeMethods.DEV_BROADCAST_DEVICEINTERFACE(); int size = Marshal.SizeOf(deviceInterface); deviceInterface.dbcc_size = size; deviceInterface.dbcc_devicetype = NativeMethods.DBT_DEVTYP_DEVICEINTERFACE; IntPtr buffer = default(IntPtr); buffer = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(deviceInterface, buffer, true); NativeMethods.RegisterDeviceNotification(radiohandle, buffer, NativeMethods.DEVICE_NOTIFY_SERVICE_HANDLE | NativeMethods.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); – Ashok Palakurthi Mar 01 '19 at 18:09
  • @mike-petrichenko I registered for the device notification like above, then Do I need to write windows message pump handler to get receive and process the messages? – Ashok Palakurthi Mar 01 '19 at 18:12
  • 1
    You should use DEV_BROADCAST_DEVICEHANDLE. But the first step you have to use BluetoothFindFirstRadio() function to get Bluetooth Radio driver object handle and use this handle in RegisterDeviceNotification() function to subscribe to notifications. – Mike Petrichenko Mar 01 '19 at 20:23
  • 1
    I am not sure if that works with DEVICE_NOTIFY_SERVICE_HANDLE. If yes, then you do not need message pump. If no then you need message pump. – Mike Petrichenko Mar 01 '19 at 20:25
  • Thank you @mike-petrichenko Do I need to assign any guid for devHandle.dcbh_eventguid ? what is that Guid value. – Ashok Palakurthi Mar 04 '19 at 14:14
  • IntPtr findhandle = NativeMethods.BluetoothFindFirstRadio(ref bfrp, out handle); NativeMethods.DEV_BROADCAST_DEVICEHANDLE devHandle = new NativeMethods.DEV_BROADCAST_DEVICEHANDLE(); devHandle.dbch_size = (uint)Marshal.SizeOf(devHandle); devHandle.dbch_devicetype = NativeMethods.DBT_DEVTYP_HANDLE; IntPtr buffer = default(IntPtr); buffer = Marshal.AllocHGlobal(Marshal.SizeOf(devHandle)); Marshal.StructureToPtr(devHandle, buffer, true); IntPtr testIntPtr = NativeMethods.RegisterDeviceNotification(handle, ref devHandle, 0); – Ashok Palakurthi Mar 04 '19 at 14:15

0 Answers0