Esempio n. 1
0
        /// <summary>
        /// Reads WAVE data from CD sectors
        /// </summary>
        /// <param name="startSector">Start sector number</param>
        /// <param name="sectorCount">Number of sectors to read</param>
        /// <param name="buffer">Buffer</param>
        /// <returns>Number of bytes read</returns>
        public uint ReadSectors(uint startSector, uint sectorCount, byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (sectorCount > MaxSectorsToRead)
            {
                throw new ArgumentOutOfRangeException("sectorCount");
            }

            UnsafeCalls.RawReadInfo rawReadInfo = new UnsafeCalls.RawReadInfo();
            rawReadInfo.DiskOffset  = startSector * 2048L;
            rawReadInfo.SectorCount = sectorCount;

            uint read = 0;

            bool result = UnsafeCalls.DeviceIoControl(hCd, UnsafeCalls.IoctlCdromRawRead,
                                                      rawReadInfo, UnsafeCalls.RawReadInfoSize,
                                                      buffer, (uint)buffer.Length, ref read, IntPtr.Zero);

            if (!result)
            {
                throw new Win32Exception(UnsafeCalls.GetLastError());
            }

            return(read);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads WAVE data from CD sectors
        /// </summary>
        /// <param name="startSector">Start sector number</param>
        /// <param name="sectorCount">Number of sectors to read</param>
        /// <param name="buffer">Buffer</param>
        /// <returns>Number of bytes read</returns>
        public uint ReadSectors(uint startSector, uint sectorCount, byte[] buffer)
        {
            if (buffer == null) throw new ArgumentNullException("buffer");
            if (sectorCount > MaxSectorsToRead) throw new ArgumentOutOfRangeException("sectorCount");

            UnsafeCalls.RawReadInfo rawReadInfo = new UnsafeCalls.RawReadInfo();
            rawReadInfo.DiskOffset = startSector * 2048L;
            rawReadInfo.SectorCount = sectorCount;

            uint read = 0;

            bool result = UnsafeCalls.DeviceIoControl(hCd, UnsafeCalls.IoctlCdromRawRead,
                rawReadInfo, UnsafeCalls.RawReadInfoSize,
                buffer, (uint)buffer.Length, ref read, IntPtr.Zero);

            if (!result) throw new Win32Exception(UnsafeCalls.GetLastError());

            return read;
        }