我想从我的C#.NET应用程序,在Win 7 64位系统上运行断开蓝牙设备。
我知道MS提供很少functionnality .Net的reguarding BT。
我搜索32feet.Net,发现如何连接,探索,获取信息,...但没有有关断开(我错过了什么?)。
然后,我在MSDN上找到IOCTL_BTH_DISCONNECT_DEVICE 。 问题是,我不明白如何调用它。 看来,我768,16使用的DeviceIoControl与平台调用,但恐怕我没有足够的.NET技术通过自己建立这个。
这里是我的时刻,其中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.IO;
namespace BtDisco
{
class Program
{
const int IOCTL_BTH_DISCONNECT_DEVICE = 0x41000c;
[DllImport("Kernel32.dll", SetLastError = false, CharSet = CharSet.Auto)]
public static extern bool DeviceIoControl(
Microsoft.Win32.SafeHandles.SafeFileHandle hDevice,
uint dwIoControlCode,
[MarshalAs(UnmanagedType.AsAny)] [In] object InBuffer,
uint nInBufferSize,
[MarshalAs(UnmanagedType.AsAny)] [Out] object OutBuffer,
uint nOutBufferSize,
ref uint pBytesReturned,
[In] ref System.Threading.NativeOverlapped Overlapped
);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern SafeFileHandle CreateFile(
string lpFileName,
[MarshalAs(UnmanagedType.U4)] FileAccess dwDesiredAccess,
[MarshalAs(UnmanagedType.U4)] FileShare dwShareMode,
IntPtr lpSecurityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition,
[MarshalAs(UnmanagedType.U4)] FileAttributes dwFlagsAndAttributes,
IntPtr hTemplateFile);
static void Main(string[] args)
{
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx
//hDev = Use CreateFile
SafeFileHandle _hdev = CreateFileR(...);
DeviceIoControl(hDev, IOCTL_BTH_DISCONNECT_DEVICE, char[] btAddr, btAddr.Length(), result, result.Length(), ref getCnt, IntPtr.Zero);
}
}
}
可能有人好心地帮我完成这个?