public static int SetCompatabilityMode() { int radioCOD = GetRadioCOD(); if (!GetInCompatabilityMode()) { L2CAPAPI.RadioMode radioMode = L2CAPAPI.RadioMode.Off; L2CAPAPI.BthGetMode(out radioMode); if (radioMode != L2CAPAPI.RadioMode.Off) { L2CAPAPI.BthSetMode(L2CAPAPI.RadioMode.Off); } try { Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Bluetooth\sys", "COD", CODCompatabilityMode); L2CAPAPI.BthSetMode(L2CAPAPI.RadioMode.Discoverable); } finally { //Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Bluetooth\sys", "COD", radioCOD); } } return(radioCOD); }
void MobileRemoteUI_Closing(object sender, CancelEventArgs e) { L2CAPAPI.RadioMode currentRadioMode = 0; L2CAPAPI.BthGetMode(out currentRadioMode); if (currentRadioMode != _initialRadioMode) { L2CAPAPI.BthSetMode(_initialRadioMode); } _hidWriter.Dispose(); }
private void ShowConnectDialog(bool autoConnect) { L2CAPAPI.RadioMode radioMode = L2CAPAPI.RadioMode.Off; L2CAPAPI.BthGetMode(out radioMode); if (radioMode != L2CAPAPI.RadioMode.Discoverable) { if (autoConnect || (DialogResult.Yes == MessageBox.Show("MobileRemote requires that Bluetooth is enabled. Would you like to enable Bluetooth on your phone?", "Bluetooth Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))) { L2CAPAPI.BthSetMode(L2CAPAPI.RadioMode.Discoverable); } else { return; } } using (AddressSelector selector = new AddressSelector()) { bool firstConnect = autoConnect && (selector.SelectedDevice.Address != 0); if (firstConnect || (DialogResult.OK == selector.ShowDialog(this))) { if (null != selector.SelectedDevice) { bool legacyMode = selector.LegacyMode; int oldMode = 0; if (legacyMode) { oldMode = Utils.SetCompatabilityMode(); } WaitHandle result = _hidWriter.ConnectAsync(selector.SelectedDevice.Address); try { using (WaitForConnection waitDialog = new WaitForConnection()) { if (DialogResult.OK != waitDialog.ShowDialog(this, result, selector.SelectedDevice, _hidWriter)) { _hidWriter.Disconnect(); } } } finally { if (legacyMode) { Utils.UnsetCompatabilityMode(oldMode); } } } } } }