📄 bthns_setblob.cs
字号:
using System;
using bluetoothX;
using System.Runtime.InteropServices;
namespace bluetoothX
{
internal class BTHNS_SETBLOB : BTHNS_BLOB
{
private const int BTH_SDP_VERSION = 1;
private GCHandle pVersionHandle;
private GCHandle pRecordHandle;
public BTHNS_SETBLOB(byte[] record)
{
//create data buffer
m_data = new byte[36 + record.Length];
pVersionHandle = GCHandle.Alloc(BTH_SDP_VERSION, GCHandleType.Pinned);
pRecordHandle = GCHandle.Alloc((int)0, GCHandleType.Pinned);
IntPtr vaddr = pVersionHandle.AddrOfPinnedObject();
IntPtr haddr = pRecordHandle.AddrOfPinnedObject();
BitConverter.GetBytes((int)vaddr).CopyTo(m_data, 0);
BitConverter.GetBytes((int)haddr).CopyTo(m_data, 4);
BitConverter.GetBytes(record.Length).CopyTo(m_data, 32);
//copy sdp record
Buffer.BlockCopy(record, 0, m_data, 36, record.Length);
}
public int Handle
{
get
{
IntPtr pHandle = (IntPtr)BitConverter.ToInt32(m_data, 4);
return Marshal.ReadInt32(pHandle);
//return m_handle;
}
set
{
IntPtr pHandle = (IntPtr)BitConverter.ToInt32(m_data, 4);
Marshal.WriteInt32(pHandle, value);
}
}
public uint CodService
{
get
{
return BitConverter.ToUInt32(m_data, 8);
}
set
{
BitConverter.GetBytes(value).CopyTo(m_data, 8);
}
}
#region IDisposable Members
protected override void Dispose(bool disposing)
{
try
{
if(pVersionHandle.IsAllocated)
{
pVersionHandle.Free();
}
if(pRecordHandle.IsAllocated)
{
pRecordHandle.Free();
}
}
finally
{
base.Dispose(disposing);
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -