bluetoothsecurity.cs

来自「蓝牙传输控件,用于蓝牙文件上传和下载。芯片只要选用crs」· CS 代码 · 共 36 行

CS
36
字号
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace bluetoothX
{
    public static class BluetoothSecurity
    {		
	    public static bool PairRequest(BluetoothAddress device, string pin)
	    {
	        BLUETOOTH_DEVICE_INFO bdi = new BLUETOOTH_DEVICE_INFO(device.ToInt64());
            int result = NativeMethods.BluetoothGetDeviceInfo(IntPtr.Zero, ref bdi);
            result = NativeMethods.BluetoothAuthenticateDevice(IntPtr.Zero, IntPtr.Zero, ref bdi, pin, pin.Length);

            if (0 != result && 259 != result)
		    {
			    return false;
		    }

		    return true;
	    }

        public static bool RemoveDevice(BluetoothAddress device)
        {
            int result = NativeMethods.BluetoothRemoveDevice(device.ToByteArray());

            if (0 == result)
            {
                return true;
            }

            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?