Пример #1
0
        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);
        }
Пример #2
0
 internal static extern UInt32 BluetoothRegisterForAuthentication(
     ref BLUETOOTH_DEVICE_INFO pbtdi,
     out BluetoothAuthenticationRegistrationHandle phRegHandle,
     BluetoothAuthenticationCallback pfnCallback,
     IntPtr pvParam);