private static BluetoothRadio GetDefault() { BLUETOOTH_FIND_RADIO_PARAMS p = BLUETOOTH_FIND_RADIO_PARAMS.Create(); BLUETOOTH_RADIO_INFO info = BLUETOOTH_RADIO_INFO.Create(); IntPtr hRadio = IntPtr.Zero; IntPtr findHandle = NativeMethods.BluetoothFindFirstRadio(ref p, out hRadio); if (hRadio != IntPtr.Zero) { int result = NativeMethods.BluetoothGetRadioInfo(hRadio, ref info); } if (findHandle != IntPtr.Zero) { NativeMethods.BluetoothFindRadioClose(findHandle); } if (hRadio != IntPtr.Zero) { return(new BluetoothRadio(info, hRadio)); } return(null); }
public static BLUETOOTH_ADDRESS?GetLocalBluetoothMacAddress() { IntPtr radioHandle = IntPtr.Zero; SafeFileHandle bluetoothHandle = null; try { BLUETOOTH_FIND_RADIO_PARAMS radioFindParams = new BLUETOOTH_FIND_RADIO_PARAMS(); radioFindParams.dwSize = Marshal.SizeOf(radioFindParams); radioHandle = BluetoothFindFirstRadio(ref radioFindParams, out bluetoothHandle); if (radioHandle == IntPtr.Zero) { Debug.WriteLine("No bluetooth radio found to get mac address for."); return(null); } BLUETOOTH_RADIO_INFO radioInfo = new BLUETOOTH_RADIO_INFO(); radioInfo.dwSize = Marshal.SizeOf(radioInfo); if (BluetoothGetRadioInfo(radioHandle, ref radioInfo)) { Debug.WriteLine("Bluetooth local mac address: " + radioInfo.address.byte1 + ":" + radioInfo.address.byte2 + ":" + radioInfo.address.byte3 + ":" + radioInfo.address.byte4 + ":" + radioInfo.address.byte5 + ":" + radioInfo.address.byte6); return(radioInfo.address); } else { return(null); } } catch (Exception ex) { Debug.WriteLine("Failed to get local bluetooth mac address: " + ex.Message); return(null); } finally { if (radioHandle != IntPtr.Zero) { BluetoothFindRadioClose(radioHandle); } if (bluetoothHandle != null) { bluetoothHandle.Dispose(); } } }
private static void GetAllRadios(List <BluetoothRadio> radios) { BLUETOOTH_FIND_RADIO_PARAMS p = BLUETOOTH_FIND_RADIO_PARAMS.Create(); BLUETOOTH_RADIO_INFO info = BLUETOOTH_RADIO_INFO.Create(); IntPtr hRadio = IntPtr.Zero; IntPtr findHandle = NativeMethods.BluetoothFindFirstRadio(ref p, out hRadio); do { if (hRadio != IntPtr.Zero) { int result = NativeMethods.BluetoothGetRadioInfo(hRadio, ref info); radios.Add(new BluetoothRadio(info, hRadio)); } }while (NativeMethods.BluetoothFindNextRadio(findHandle, out hRadio)); if (findHandle != IntPtr.Zero) { NativeMethods.BluetoothFindRadioClose(findHandle); } }
public extern static UInt32 MyBluetoothGetRadioInfo( IntPtr hRadio, ref BLUETOOTH_RADIO_INFO pRadioInfo );
public static extern int BluetoothGetRadioInfo(IntPtr hRadio, ref BLUETOOTH_RADIO_INFO pbtdi);
private BluetoothRadio(BLUETOOTH_RADIO_INFO info, IntPtr handle) { _radio = info; _handle = handle; }
public static extern uint BluetoothGetRadioInfo( IntPtr hRadio, ref BLUETOOTH_RADIO_INFO pRadioInfo);