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 And Writing On The Same File

Reading And Writing On The Same File

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 4 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.
  • J Offline
    J Offline
    jannathali
    wrote on last edited by
    #1

    Hai, I am having two applications that run simultaneously. One program writes data to a file and the other program reads data from that file itself and performs some operations based on the value of that file.The problem is that since both are using same file there will be a chance to request to read the file while the file is writing.Is there any method 2 use a single file for two programs.

    _ K 2 Replies Last reply
    0
    • J jannathali

      Hai, I am having two applications that run simultaneously. One program writes data to a file and the other program reads data from that file itself and performs some operations based on the value of that file.The problem is that since both are using same file there will be a chance to request to read the file while the file is writing.Is there any method 2 use a single file for two programs.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Use CreateFile to open the file and specify the dwShareMode parameter as FILE_SHARE_READ|FILE_SHARE_WRITE.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      1 Reply Last reply
      0
      • J jannathali

        Hai, I am having two applications that run simultaneously. One program writes data to a file and the other program reads data from that file itself and performs some operations based on the value of that file.The problem is that since both are using same file there will be a chance to request to read the file while the file is writing.Is there any method 2 use a single file for two programs.

        K Offline
        K Offline
        KingsGambit
        wrote on last edited by
        #3

        In addition to what _superman_ has mentioned, you may have to use a notification methode like an event (http://msdn.microsoft.com/en-us/library/ms686915(VS.85).aspx[^]) so that the first app can notify the other app when it is ready for the read.

        V 1 Reply Last reply
        0
        • K KingsGambit

          In addition to what _superman_ has mentioned, you may have to use a notification methode like an event (http://msdn.microsoft.com/en-us/library/ms686915(VS.85).aspx[^]) so that the first app can notify the other app when it is ready for the read.

          V Offline
          V Offline
          vkpMark
          wrote on last edited by
          #4

          you can use thread mutex

          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