Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
i'm trying to read CD/DVD bytes.
But when Stream() is Seek() over to 102400 offset, ReadByte() returns -1. It's problem only for CD discs.
Here's my code:

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern SafeFileHandle CreateFile(string lpFileName,
            FileAccess dwDesiredAccess,
            FileShare dwShareMode,
            uint lpSecurityAttributes,
            FileMode dwCreationDisposition,
            int flagsAndAttributes,
            uint hTemplateFile);
 
Microsoft.Win32.SafeHandles.SafeFileHandle handle = null;
handle = CreateFile("\\\\.\\E:",
                    FileAccess.Read,
                    FileShare.Read,
                    0,
                    FileMode.Open,
                    FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN,
                    0);
 
Stream strm= new FileStream(handle, FileAccess.Read);
 
strm.Seek(24608768, SeekOrigin.Begin); 
 
int dt=strm.ReadByte(); // here it returns -1 


How can i read all of the disc bytes?

[edit]"Ignore HTML..." option disabled to allow code block to work - OriginalGriff[/edit]
Posted
Updated 29-Mar-11 22:15pm
v2

No wonder: you're trying to read directory; why do you expect so much data in it?
Moreover, you cannot assume the directory if "E:"; it depends. (On one of my systems E: is the system boot disk with Windows, why not?)

I think you what to read a physical disk. Read this to see how to do it: http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx[^].

—SA
 
Share this answer
 
v2
Maybe this article helps? C Sharp Ripper[^]
 
Share this answer
 
Comments
umutx 30-Mar-11 7:16am    
thanks johannesnestler
i'll try this.
Hope to work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900