📄 nativemethods.cs
字号:
using System;
using System.Runtime.InteropServices;
using bluetoothX;
namespace bluetoothX
{
internal static class NativeMethods
{
private const string wsDll = "ws2_32.dll";
[DllImport(wsDll, EntryPoint="WSAGetLastError", SetLastError=true)]
public static extern int WSAGetLastError();
//SetService
[DllImport(wsDll, EntryPoint = "WSASetService", SetLastError = true)]
public static extern int WSASetService(ref WSAQUERYSET lpqsRegInfo, WSAESETSERVICEOP essoperation, int dwControlFlags);
//LookupService
[DllImport(wsDll, EntryPoint = "WSALookupServiceBegin", SetLastError = true)]
public static extern int WSALookupServiceBegin(byte[] pQuerySet, LookupFlags dwFlags, ref int lphLookup);
[DllImport(wsDll, EntryPoint = "WSALookupServiceBegin", SetLastError = true)]
public static extern int WSALookupServiceBegin(ref WSAQUERYSET pQuerySet, LookupFlags dwFlags, ref int lphLookup);
[DllImport(wsDll, EntryPoint="WSALookupServiceNext", SetLastError=true)]
public static extern int WSALookupServiceNext(int hLookup, LookupFlags dwFlags, ref int lpdwBufferLength, byte[] pResults);
[DllImport(wsDll, EntryPoint="WSALookupServiceEnd", SetLastError=true)]
public static extern int WSALookupServiceEnd(int hLookup);
[DllImport("Irprops.cpl", SetLastError=true, CharSet=CharSet.Unicode)]
public static extern int BluetoothAuthenticateDevice(IntPtr hwndParent, IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, string pszPasskey, int ulPasskeyLength);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothDisplayDeviceProperties(IntPtr hwndParent, ref BLUETOOTH_DEVICE_INFO pbtdi);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothEnableDiscovery(IntPtr hRadio, bool fEnabled);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothEnableIncomingConnections(IntPtr hRadio, bool fEnabled);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern int BluetoothEnumerateInstalledServices(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, ref int pcServices, byte[] pGuidServices);
[DllImport("Irprops.cpl", SetLastError = true)]
public static extern int BluetoothSetServiceState(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, ref Guid pGuidService, int dwServiceFlags);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern IntPtr BluetoothFindFirstRadio(ref BLUETOOTH_FIND_RADIO_PARAMS pbtfrp, ref IntPtr phRadio);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothFindNextRadio(IntPtr hFind, ref IntPtr phRadio);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothFindRadioClose(IntPtr hFind);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern int BluetoothGetDeviceInfo(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern int BluetoothGetRadioInfo(IntPtr hRadio, ref BLUETOOTH_RADIO_INFO pRadioInfo);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothIsConnectable(IntPtr hRadio);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern bool BluetoothIsDiscoverable(IntPtr hRadio);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern int BluetoothUpdateDeviceRecord(ref BLUETOOTH_DEVICE_INFO pbtdi);
//XP SDP Parsing
[DllImport("Irprops.cpl", SetLastError = true)]
public static extern int BluetoothSdpGetAttributeValue(byte[] pRecordStream, int cbRecordLength, ushort usAttributeId, IntPtr pAttributeData);
[DllImport("Irprops.cpl", SetLastError = true)]
public static extern int BluetoothSdpGetContainerElementData(byte[] pContainerStream, uint cbContainerLength, ref IntPtr pElement, byte[] pData);
[DllImport("Irprops.cpl", SetLastError = true)]
public static extern int BluetoothSdpGetElementData(byte[] pSdpStream, uint cbSpdStreamLength, byte[] pData);
[DllImport("Irprops.cpl", SetLastError=true)]
public static extern int BluetoothSdpGetString(byte[] pRecordStream, uint cbRecordLength,
IntPtr pStringData, ushort usStringOffset, byte[] pszString, ref uint pcchStringLength);
[DllImport("Irprops.cpl", SetLastError=true, CharSet=CharSet.Unicode)]
public static extern int BluetoothSendAuthenticationResponse(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, string pszPasskey);
[DllImport("Irprops.cpl", SetLastError=true, CharSet=CharSet.Unicode)]
public static extern int BluetoothRemoveDevice(byte[] pAddress);
}
internal enum WSAESETSERVICEOP : int
{
RNRSERVICE_REGISTER = 0,
RNRSERVICE_DEREGISTER,
RNRSERVICE_DELETE,
}
[Flags()]
internal enum LookupFlags : uint
{
Containers = 0x0002,
ReturnName = 0x0010,
ReturnAddr = 0x0100,
ReturnBlob = 0x0200,
FlushCache = 0x1000,
ResService = 0x8000,
}
[Flags()]
internal enum ScanMask : byte
{
None = 0,
Inquiry = 1,
Page = 2,
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -