Reading sectors
-
Good idea. I have few troubles with accessing USB drive with CFile, but once I'll solve it, the code will be simple. Here is my trial, none on them has worked:
file.Open(_T("\\\\.\\F:"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
file.Open(_T("F:"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
file.Open(_T("F:\\"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
HANDLE hVolume = ::CreateFile(sVolume, GENERIC\_READ, FILE\_SHARE\_READ | FILE\_SHARE\_WRITE, NULL, OPEN\_EXISTING, FILE\_FLAG\_SEQUENTIAL\_SCAN, NULL); CFile file(hVolume); CFileStatus status; file.GetStatus(status); // return FALSE
When using CFile::Open you should pass the CFileException* parameter to get the failure cause if CFile::Open fails. See the example in [CFile::Open](https://docs.microsoft.com/en-us/cpp/mfc/reference/cfile-class?view=vs-2019#open)
-
Good idea. I have few troubles with accessing USB drive with CFile, but once I'll solve it, the code will be simple. Here is my trial, none on them has worked:
file.Open(_T("\\\\.\\F:"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
file.Open(_T("F:"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
file.Open(_T("F:\\"), CFile::modeRead | CFile::osSequentialScan); // return FALSE
HANDLE hVolume = ::CreateFile(sVolume, GENERIC\_READ, FILE\_SHARE\_READ | FILE\_SHARE\_WRITE, NULL, OPEN\_EXISTING, FILE\_FLAG\_SEQUENTIAL\_SCAN, NULL); CFile file(hVolume); CFileStatus status; file.GetStatus(status); // return FALSE
-
It is just the same as
OpenFile
behind the scenes so nothing to do withCFile
. Your call probably fails because you are not including the share flags in your call to CFile::Open(), which are required when trying to access a device.