Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reading sectors

Reading sectors

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestionworkspace
23 Posts 5 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ _Flaviu

    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
    
    V Offline
    V Offline
    Victor Nijegorodov
    wrote on last edited by
    #21

    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)

    1 Reply Last reply
    0
    • _ _Flaviu

      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
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #22

      It is just the same as OpenFile behind the scenes so nothing to do with CFile. 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.

      _ 1 Reply Last reply
      0
      • L Lost User

        It is just the same as OpenFile behind the scenes so nothing to do with CFile. 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.

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #23

        Thanks, solved.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups