Click here to Skip to main content
15,895,777 members
Articles / Programming Languages / C#

SCSI Library in C# - Burn CDs and DVDs, Access Hard Disks, etc.

Rate me:
Please Sign up or sign in to vote.
4.77/5 (48 votes)
19 Jun 2017Ms-PL6 min read 146.2K   8.1K   146  
Ever wonder how programs like Nero work? They make their own SCSI libraries... like this!
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Helper;

namespace Scsi.Multimedia
{
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public class AbsoluteTimeInPregroove : TocPmaAtipResponseData
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private static readonly IntPtr SPECIAL_INFORMATION_OFFSET = Marshal.OffsetOf(typeof(AbsoluteTimeInPregroove), "_SpecialInformation");
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private static readonly IntPtr ADDITIONAL_INFORMATION_OFFSET = Marshal.OffsetOf(typeof(AbsoluteTimeInPregroove), "_AdditionalInformation");

		public AbsoluteTimeInPregroove() : base() { }

		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
		private int[] _SpecialInformation;
		//TODO: The special information has a very specific format but I haven't implemented it yet.
		public int[] SpecialInformation { get { return this._SpecialInformation; } set { this._SpecialInformation = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
		private int[] _AdditionalInformation;
		//TODO: The additional information has a very specific format but I haven't implemented it yet.
		public int[] AdditionalInformation { get { return this._AdditionalInformation; } set { this._AdditionalInformation = value; } }


		protected override void MarshalFrom(BufferWithSize buffer)
		{
			base.MarshalFrom(buffer);
			this._SpecialInformation = new int[3];
			Marshal.Copy(buffer.ExtractSegment((int)SPECIAL_INFORMATION_OFFSET, this._SpecialInformation.Length * sizeof(int)).Address, this._SpecialInformation, 0, this._SpecialInformation.Length);
			this._AdditionalInformation = new int[3];
			Marshal.Copy(buffer.ExtractSegment((int)ADDITIONAL_INFORMATION_OFFSET, this._AdditionalInformation.Length * sizeof(int)).Address, this._AdditionalInformation, 0, this._AdditionalInformation.Length);
		}

		protected override void MarshalTo(BufferWithSize buffer)
		{
			base.MarshalTo(buffer);
			if (this._SpecialInformation.Length > 3) { throw new OverflowException("Field is too large."); }
			Marshal.Copy(this._SpecialInformation, 0, buffer.ExtractSegment((int)SPECIAL_INFORMATION_OFFSET, this._SpecialInformation.Length * sizeof(int)).Address, this._SpecialInformation.Length);
			buffer.Initialize((int)SPECIAL_INFORMATION_OFFSET + this._SpecialInformation.Length, 3 - this._SpecialInformation.Length);
			if (this._AdditionalInformation.Length > 3) { throw new OverflowException("Field is too large."); }
			Marshal.Copy(this._AdditionalInformation, 0, buffer.ExtractSegment((int)ADDITIONAL_INFORMATION_OFFSET, this._AdditionalInformation.Length * sizeof(int)).Address, this._AdditionalInformation.Length);
			buffer.Initialize((int)ADDITIONAL_INFORMATION_OFFSET + this._AdditionalInformation.Length, 3 - this._AdditionalInformation.Length);
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		protected override int MarshaledSize { get { return Marshaler.DefaultSizeOf<AbsoluteTimeInPregroove>(); } }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions