Ejemplo n.º 1
0
 internal static extern bool DeviceIoControl(
     SafeFileHandle hDevice,
     uint IoControlCode,
     [In] RawReadInfo InBuffer,
     uint nInBufferSize,
     [Out] byte[] OutBuffer,
     uint nOutBufferSize,
     ref uint pBytesReturned,
     [In] IntPtr Overlapped
     );
Ejemplo n.º 2
0
        private bool ReadSector(int sector, byte[] Buffer, int NumSectors)
        {
            if (_tocIsValid &&
                ((sector + NumSectors) <= GetEndSector(_Toc.LastTrack)) &&
                (Buffer.Length >= CdConstants.CB_AUDIO * NumSectors) &&
                _driveHandle != null)
            {
                RawReadInfo rri = new RawReadInfo();
                rri.TrackMode   = TrackModeType.CDDA;
                rri.SectorCount = (uint)NumSectors;
                rri.DiskOffset  = sector * CdConstants.CB_CDROMSECTOR;

                uint BytesRead = 0;

                var input = GCHandle.Alloc(rri, GCHandleType.Pinned);

                var output = GCHandle.Alloc(Buffer, GCHandleType.Pinned);


                NativeOverlapped overlaped = default;
                bool             result    = NativeMethods.DeviceIoControl(_driveHandle,
                                                                           EIOControlCode.CDromRawRead,
                                                                           input.AddrOfPinnedObject(),
                                                                           (uint)Marshal.SizeOf(rri),
                                                                           output.AddrOfPinnedObject(), //TEST
                                                                           (uint)NumSectors * CdConstants.CB_AUDIO,
                                                                           ref BytesRead,
                                                                           ref overlaped);

                input.Free();
                output.Free();

                return(result);
            }
            else
            {
                return(false);
            }
        }