private void start_auth() { BluetoothAuthenticationRegistrationHandle phRegHandle = null; NativeMethods.BluetoothFindRadioParams @params; @params.size = 4; IntPtr zero = IntPtr.Zero; NativeMethods.BluetoothFindFirstRadio(ref @params, out zero); if (!NativeMethods.BluetoothEnableDiscovery(zero, true)) { this.authTextbox("错误2:设置蓝牙适配器可见失败!\r\n"); } else if (!NativeMethods.BluetoothEnableIncomingConnections(zero, true)) { this.authTextbox("错误3:设置蓝牙适配器可连接失败!\r\n"); } else { BLUETOOTH_DEVICE_INFO pbtdi = new BLUETOOTH_DEVICE_INFO(0L); if (NativeMethods.BluetoothRegisterForAuthentication(ref pbtdi, out phRegHandle, new NativeMethods.BluetoothAuthenticationCallback(this.auth_callback_ex), IntPtr.Zero) == 0) { this.authTextbox("自动配对......."); } } }
internal static extern UInt32 BluetoothRegisterForAuthenticationEx( ref BLUETOOTH_DEVICE_INFO pbtdi, out BluetoothAuthenticationRegistrationHandle phRegHandle, BluetoothAuthenticationCallbackEx pfnCallback, IntPtr pvParam);