private bool ReadTOC() { if (_driveHandle?.IsInvalid == false) { uint BytesRead = 0; NativeOverlapped overlaped = default; byte[] buffer = new byte[Marshal.SizeOf(_Toc)]; GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); _tocIsValid = NativeMethods.DeviceIoControl(_driveHandle, EIOControlCode.CDromReadTOC, IntPtr.Zero, 0, handle.AddrOfPinnedObject(), (uint)Marshal.SizeOf(_Toc), ref BytesRead, ref overlaped); object?result = Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(CdromTOC)); if (result != null) { _Toc = (CdromTOC)result; } else { _tocIsValid = false; } handle.Free(); } else { _tocIsValid = false; } return(_tocIsValid); }
public CdReader() { _driveLetter = '\0'; _Toc = new CdromTOC(); }