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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| using System.Diagnostics;
//using Windows.Devices.Enumeration;
//using Windows.Devices.PointOfService;
using Windows.Devices.Enumeration;
using Windows.Devices.PointOfService;
using System.Runtime.InteropServices;
using static System.ComponentModel.Design.ObjectSelectorEditor;
[StructLayout(LayoutKind.Sequential)]
public struct BLUETOOTH_DEVICE_INFO
{
public uint dwSize;
public ulong Address;
public uint ulClassofDevice;
public bool fConnected;
public bool fRemembered;
public bool fAuthenticated;
//public SYSTEMTIME stLastSeen;
//public SYSTEMTIME stLastUsed;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 248)]
public string szName;
public uint ulFlags;
}
namespace WinFormsApp1
{
public partial class Form1 : Form
{
//private static extern uint BluetoothSetServiceState(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, ref Guid pGuidService, uint dwServiceFlags);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
test();
}
private void test()
{
SetBluetooth(true);
}
//[DllImport("Irprops.cpl", CharSet = CharSet.Auto, SetLastError = true)]
//static extern int BluetoothSetServiceState(IntPtr handle, ref BLUETOOTH_DEVICE_INFO deviceInfo, ref Guid guidService, uint serviceFlags);
[DllImport("Irprops.cpl", CharSet = CharSet.Auto, SetLastError = true)]
static extern int BluetoothEnableDiscovery(IntPtr handle, bool bascule);
public static void SetBluetooth(bool enable)
{
//BLUETOOTH_DEVICE_INFO deviceInfo = new BLUETOOTH_DEVICE_INFO();
//deviceInfo.dwSize = Convert.ToUInt32(Marshal.SizeOf(deviceInfo));
//deviceInfo.Address = 0;//new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//deviceInfo.ulClassofDevice = 0x200404;
//deviceInfo.fConnected = false;
//deviceInfo.fRemembered = false;
//deviceInfo.fAuthenticated = false;
//deviceInfo.szName = "toto";// new byte[248];
//deviceInfo.ulFlags = 0;
//Guid serviceClass = new Guid(0x00001101, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
//uint serviceFlags = enable ? 1u : 0u;
//BluetoothSetServiceState(IntPtr.Zero, ref deviceInfo, ref serviceClass, serviceFlags);
BluetoothEnableDiscovery(IntPtr.Zero, enable);
}
}
} |
Partager