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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFile open and create file

CFile open and create file

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++json
4 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.
  • A Offline
    A Offline
    ashokvishnu
    wrote on last edited by
    #1

    I want to lock a file so that another application will not be able to open it. I am using CFile.open method with the flags CFile::modeRead|CFile::shareExclusive. However, after opening the file (and keeping it open) I am able to open the file using the windows api CreateFile function. How can I lock the file so that, the CreateFile function will fail?

    C++beginer

    P 1 Reply Last reply
    0
    • A ashokvishnu

      I want to lock a file so that another application will not be able to open it. I am using CFile.open method with the flags CFile::modeRead|CFile::shareExclusive. However, after opening the file (and keeping it open) I am able to open the file using the windows api CreateFile function. How can I lock the file so that, the CreateFile function will fail?

      C++beginer

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      ashokvishnu wrote:

      I am able to open the file using the windows api CreateFile function.

      Can you show code ?

      Prasad Notifier using ATL | Operator new[],delete[][^]

      A 1 Reply Last reply
      0
      • P prasad_som

        ashokvishnu wrote:

        I am able to open the file using the windows api CreateFile function.

        Can you show code ?

        Prasad Notifier using ATL | Operator new[],delete[][^]

        A Offline
        A Offline
        ashokvishnu
        wrote on last edited by
        #3

        I found out the problem. If you use createfile function with dwDesiredAccess flag as 0, then it will not try to open the file. It will only check whether the file exists.

        C++beginer

        CPalliniC 1 Reply Last reply
        0
        • A ashokvishnu

          I found out the problem. If you use createfile function with dwDesiredAccess flag as 0, then it will not try to open the file. It will only check whether the file exists.

          C++beginer

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          ashokvishnu wrote:

          I found out the problem. If you use createfile function with dwDesiredAccess flag as 0, then it will not try to open the file. It will only check whether the file exists.

          I don't think that is a solution, at least for the problem you posted. What will happen if another application tries to open your file?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          In testa che avete, signor di Ceprano?

          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