1 回答
TA贡献1884条经验 获得超4个赞
要取消经典蓝牙设备,您必须调用BluetoothRemoveDevice函数。
对于.NET,它可以按如下方式导入
[StructLayout(LayoutKind.Explicit)]
struct BLUETOOTH_ADDRESS
{
[FieldOffset(0)]
[MarshalAs(UnmanagedType.I8)]
public Int64 ullLong;
[FieldOffset(0)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_0;
[FieldOffset(1)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_1;
[FieldOffset(2)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_2;
[FieldOffset(3)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_3;
[FieldOffset(4)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_4;
[FieldOffset(5)]
[MarshalAs(UnmanagedType.U1)]
public Byte rgBytes_5;
};
[DllImport("BluetoothAPIs.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.U4)]
static extern UInt32 BluetoothRemoveDevice(
[param: In, Out] ref BLUETOOTH_ADDRESS pAddress);
以下是如何调用它:
UInt32 Unpair(Int64 Address)
{
BLUETOOTH_ADDRESS Addr = new BLUETOOTH_ADDRESS();
Addr.ullLong = Address;
return BluetoothRemoveDevice(ref Addr);
}
请注意,此功能仅允许取消配对经典蓝牙设备。要取消配对蓝牙 LE 设备,您必须使用基于 WinRT 的其他方式。
- 1 回答
- 0 关注
- 318 浏览
添加回答
举报