forked from nefarius/BthPS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BluetoothHelper.cs
54 lines (44 loc) · 1.64 KB
/
BluetoothHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using BthPS3CfgUI.Annotations;
namespace BthPS3CfgUI
{
public static class BluetoothHelper
{
[UsedImplicitly]
public static bool IsBluetoothRadioAvailable
{
get
{
var radioParams = new BLUETOOTH_FIND_RADIO_PARAMS();
radioParams.Init();
var findHandle = BluetoothFindFirstRadio(ref radioParams, out var radioHandle);
if (findHandle == IntPtr.Zero) return false;
BluetoothFindRadioClose(findHandle);
CloseHandle(radioHandle);
return true;
}
}
[DllImport("BluetoothApis.dll", SetLastError = true)]
private static extern IntPtr
BluetoothFindFirstRadio(ref BLUETOOTH_FIND_RADIO_PARAMS pbtfrp, out IntPtr phRadio);
[DllImport("BluetoothApis.dll", SetLastError = true)]
private static extern bool BluetoothFindRadioClose(IntPtr hFind);
[DllImport("kernel32.dll", SetLastError = true)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
[StructLayout(LayoutKind.Sequential)]
private struct BLUETOOTH_FIND_RADIO_PARAMS
{
public uint dwSize;
public void Init()
{
dwSize = (uint) Marshal.SizeOf(typeof(BLUETOOTH_FIND_RADIO_PARAMS));
}
}
}
}