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. CreateFile - " file is being used by another process." [modified]

CreateFile - " file is being used by another process." [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 3 Posters 0 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.
  • C Offline
    C Offline
    Cvaji
    wrote on last edited by
    #1

    Hi All, I am using CreateFile to open a specific file which will be accessed by multiple instance of same process simultaneously. This time function getting failed and GetLastError() is returning the following error. "The process cannot access the file because it is being used by another process." This is how i called the function

    hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
    if( INVALID_HANDLE_VALUE == hFile )
    {
    CString csErr;
    csErr.Format( _T("Failed to open File**** Error code = %d"), GetLastError());
    AfxMessageBox( csErr );
    return bRet;
    }

    I need to open the same file simultaneously by different process. Please help me. -Cvaji

    modified on Thursday, July 15, 2010 9:30 AM

    N N C 3 Replies Last reply
    0
    • C Cvaji

      Hi All, I am using CreateFile to open a specific file which will be accessed by multiple instance of same process simultaneously. This time function getting failed and GetLastError() is returning the following error. "The process cannot access the file because it is being used by another process." This is how i called the function

      hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
      if( INVALID_HANDLE_VALUE == hFile )
      {
      CString csErr;
      csErr.Format( _T("Failed to open File**** Error code = %d"), GetLastError());
      AfxMessageBox( csErr );
      return bRet;
      }

      I need to open the same file simultaneously by different process. Please help me. -Cvaji

      modified on Thursday, July 15, 2010 9:30 AM

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      Is one of your processes writing to the file (looking at your other question)? In that case you need to specify the sharing mode there too.

      home

      1 Reply Last reply
      0
      • C Cvaji

        Hi All, I am using CreateFile to open a specific file which will be accessed by multiple instance of same process simultaneously. This time function getting failed and GetLastError() is returning the following error. "The process cannot access the file because it is being used by another process." This is how i called the function

        hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
        if( INVALID_HANDLE_VALUE == hFile )
        {
        CString csErr;
        csErr.Format( _T("Failed to open File**** Error code = %d"), GetLastError());
        AfxMessageBox( csErr );
        return bRet;
        }

        I need to open the same file simultaneously by different process. Please help me. -Cvaji

        modified on Thursday, July 15, 2010 9:30 AM

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        Cvaji wrote:

        hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );if( INVALID_HANDLE_VALUE == hSMPFile )

        The return value of the CreateFile is stored in **hFile**, but you have checked the INVALID_HANDLE_VALUE aganist **hSMPFile** file. Is it really like that in the code or its just a typo?

        nave [My Articles] [My Blog]

        C 1 Reply Last reply
        0
        • C Cvaji

          Hi All, I am using CreateFile to open a specific file which will be accessed by multiple instance of same process simultaneously. This time function getting failed and GetLastError() is returning the following error. "The process cannot access the file because it is being used by another process." This is how i called the function

          hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
          if( INVALID_HANDLE_VALUE == hFile )
          {
          CString csErr;
          csErr.Format( _T("Failed to open File**** Error code = %d"), GetLastError());
          AfxMessageBox( csErr );
          return bRet;
          }

          I need to open the same file simultaneously by different process. Please help me. -Cvaji

          modified on Thursday, July 15, 2010 9:30 AM

          C Offline
          C Offline
          Cvaji
          wrote on last edited by
          #4

          Even though my application is only doing the file read,

          ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );

          this made it work. Strange :confused: :)

          1 Reply Last reply
          0
          • N Naveen

            Cvaji wrote:

            hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );if( INVALID_HANDLE_VALUE == hSMPFile )

            The return value of the CreateFile is stored in **hFile**, but you have checked the INVALID_HANDLE_VALUE aganist **hSMPFile** file. Is it really like that in the code or its just a typo?

            nave [My Articles] [My Blog]

            C Offline
            C Offline
            Cvaji
            wrote on last edited by
            #5

            sorry my friend..its just a mistake.. :)

            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