public Win32BluetoothAuthentication(BluetoothAddress address, string pin) { Address = address; _pin = pin; BLUETOOTH_DEVICE_INFO device = BLUETOOTH_DEVICE_INFO.Create(); device.Address = address; Win32Native.BluetoothGetDeviceInfo(IntPtr.Zero, ref device); _callback = new BluetoothAuthenticationCallbackEx(Callback); int result = Win32Native.BluetoothRegisterForAuthenticationEx(ref device, out _handle, _callback, IntPtr.Zero); }
private void Register(BluetoothAddress remoteAddress) { System.Diagnostics.Debug.Assert(m_pin == null ^ m_userCallback == null); // m_callback = new BluetoothAuthenticationCallback(NativeCallback); m_callbackEx = new BluetoothAuthenticationCallbackEx(NativeCallback); BLUETOOTH_DEVICE_INFO bdi = new BLUETOOTH_DEVICE_INFO(remoteAddress); uint ret; if (m_hasKB942567) { try { ret = NativeMethods.BluetoothRegisterForAuthenticationEx( ref bdi, out m_regHandle, m_callbackEx, IntPtr.Zero); } catch (EntryPointNotFoundException) { m_hasKB942567 = false; ret = NativeMethods.BluetoothRegisterForAuthentication( ref bdi, out m_regHandle, m_callback, IntPtr.Zero); } } else { ret = NativeMethods.BluetoothRegisterForAuthentication( ref bdi, out m_regHandle, m_callback, IntPtr.Zero); } int gle = Marshal.GetLastWin32Error(); System.Diagnostics.Debug.Assert(ret == NativeErrorSuccess, "BluetoothRegisterForAuthentication failed, GLE=" + gle.ToString() + "=0x" + gle.ToString("X")); if (ret != NativeErrorSuccess) { throw new System.ComponentModel.Win32Exception(gle); } m_regHandle.SetObjectToKeepAlive(m_callback, m_callbackEx); }
internal static extern int BluetoothRegisterForAuthenticationEx(ref BLUETOOTH_DEVICE_INFO pbtdi, out IntPtr phRegHandle, BluetoothAuthenticationCallbackEx pfnCallback, IntPtr pvParam);