⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blob.cs

📁 蓝牙传输控件,用于蓝牙文件上传和下载。芯片只要选用crs
💻 CS
字号:
using System;
using System.Runtime.InteropServices;
using bluetoothX;


namespace bluetoothX
{
    [StructLayout(LayoutKind.Sequential, Size=8)]
    internal struct BLOB
    {
        public int cbSize;
        public IntPtr pBlobData;

        internal BLOB(int size, IntPtr data)
        {
            cbSize = size;
            pBlobData = data;
        }
    }
    
	internal class oBLOB : IDisposable
	{
		private byte[] data = new byte[8];

		private GCHandle m_blobhandle;
		private BTHNS_BLOB m_blob;

		public int cbSize
		{
			get
			{
				return BitConverter.ToInt32(data, 0);
			}
            set
            {
                BitConverter.GetBytes(value).CopyTo(data, 0);
            }
		}

		public object pBlobData
		{
			get
			{
				return m_blob;
			}
            set
            {
                if (value is BTHNS_BLOB)
                {
                    m_blob = (BTHNS_BLOB)value;
                    m_blobhandle = GCHandle.Alloc(((BTHNS_BLOB)value).ToByteArray(), GCHandleType.Pinned);

                    //write to the byte array
                    BitConverter.GetBytes(m_blobhandle.AddrOfPinnedObject().ToInt32()).CopyTo(data, 4);
                }
                else
                {
                    m_blobhandle = GCHandle.Alloc(value, GCHandleType.Pinned);

                    //write to the byte array
                    BitConverter.GetBytes(m_blobhandle.AddrOfPinnedObject().ToInt32()).CopyTo(data, 4);
                }
            }
		}

		public byte[] ToByteArray()
		{
			return data;
		}

		#region IDisposable Members

		protected void Dispose(bool disposing)
		{
			if(m_blobhandle.IsAllocated)
			{
				m_blobhandle.Free();
			}

			if(disposing)
			{
				m_blob = null;
				data = null;
			}
		}

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
		}

		~oBLOB()
		{
			Dispose(false);
		}

		#endregion
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -