📄 wsaqueryset.cs
字号:
using System;
using System.Runtime.InteropServices;
using bluetoothX;
namespace bluetoothX
{
[StructLayout(LayoutKind.Sequential, Size=60)]
internal struct WSAQUERYSET
{
public int dwSize;
[MarshalAs(UnmanagedType.LPStr)]
public string lpszServiceInstanceName;
public IntPtr lpServiceClassId;
IntPtr lpVersion;
IntPtr lpszComment;
public int dwNameSpace;
IntPtr lpNSProviderId;
[MarshalAs(UnmanagedType.LPStr)]
public string lpszContext;
int dwNumberOfProtocols;
IntPtr lpafpProtocols;
IntPtr lpszQueryString;
public int dwNumberOfCsAddrs;
public IntPtr lpcsaBuffer;
int dwOutputFlags;
public IntPtr lpBlob;
}
internal class WsaQuerySet : IDisposable
{
public const int Length = 60;
private byte[] data;
private oBLOB blob;
private GCHandle blobHandle;
public WsaQuerySet()
{
data = new byte[60];
//write size
BitConverter.GetBytes((int)60).CopyTo(data, 0);
//set namespace
BitConverter.GetBytes((int)16).CopyTo(data, 20);
}
public byte[] ToByteArray()
{
return data;
}
public void Dispose()
{
if(blobHandle.IsAllocated)
{
blobHandle.Free();
}
}
public string ServiceInstanceName
{
get
{
return Marshal.PtrToStringUni((IntPtr)BitConverter.ToInt32(data, 4));
}
}
public Guid ServiceClassId
{
get
{
IntPtr pGuid = (IntPtr)BitConverter.ToInt32(data, 8);
byte[] guidbytes = new byte[16];
Marshal.Copy(pGuid, guidbytes, 0, 16);
return new Guid(guidbytes);
}
}
public BTHNS_BLOB Blob
{
get
{
return (BTHNS_BLOB)blob.pBlobData;
}
set
{
blob = new oBLOB();
blob.cbSize = value.Length;
blob.pBlobData = value;
//free old handle
if(blobHandle.IsAllocated)
{
blobHandle.Free();
}
if(value != null)
{
blobHandle = GCHandle.Alloc(blob.ToByteArray(), GCHandleType.Pinned);
BitConverter.GetBytes(blobHandle.AddrOfPinnedObject().ToInt32()).CopyTo(data, 56);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -