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. Unable to open a file

Unable to open a file

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

    Hi, I have created a MDI using MFC Application. The application is developed to process some input files and create an output file. At the end of the process, after the output file is created, iam trying to open the same. But its popping an error message saying "A sharing violation occured while accessing C:\temp\output.txt" And, iam not able to open it through any other application and the popping error message is "The document C:\temp\output.txt is being used by another application and cannot be accessed". I have properly coded on file opening and file closing. But still, iam not able to understand on why the problem occurs. Only, when i close my MFC application, iam able to access the created output file through any applicaton. Could someone, please help me, to get out of this situation. I thank in advance. Thanx Mughi Mughilan

    Y T 2 Replies Last reply
    0
    • M Mughi

      Hi, I have created a MDI using MFC Application. The application is developed to process some input files and create an output file. At the end of the process, after the output file is created, iam trying to open the same. But its popping an error message saying "A sharing violation occured while accessing C:\temp\output.txt" And, iam not able to open it through any other application and the popping error message is "The document C:\temp\output.txt is being used by another application and cannot be accessed". I have properly coded on file opening and file closing. But still, iam not able to understand on why the problem occurs. Only, when i close my MFC application, iam able to access the created output file through any applicaton. Could someone, please help me, to get out of this situation. I thank in advance. Thanx Mughi Mughilan

      Y Offline
      Y Offline
      Yulianto
      wrote on last edited by
      #2

      What`s your code at your file closing. I think that`s where the problem is.


      Work hard and a bit of luck is the key to success.

      :)

      M 1 Reply Last reply
      0
      • Y Yulianto

        What`s your code at your file closing. I think that`s where the problem is.


        Work hard and a bit of luck is the key to success.

        :)

        M Offline
        M Offline
        Mughi
        wrote on last edited by
        #3

        Hi, Here is the code. FILE *fp = fopen(this->output,"w"); fprintf(fp,"8\n"); for(rc=0;rc<9;rc++) for(gc=0;gc<9;gc++) for(bc=0;bc<9;bc++) { lut[0][rc][gc][bc] = (lut[0][rc][gc][bc]>255)?255:lut[0][rc][gc][bc]; lut[1][rc][gc][bc] = (lut[1][rc][gc][bc]>255)?255:lut[1][rc][gc][bc]; lut[2][rc][gc][bc] = (lut[2][rc][gc][bc]>255)?255:lut[2][rc][gc][bc]; fprintf(fp,"%d %d %d\n",lut[0][rc][gc][bc],lut[1][rc][gc][bc],lut[2][rc][gc][bc]); } fclose(fp); When my MFC application still runs, Iam able to open the file in dos prompt, but not in any of WIN32 application or in my own MFC application. Am still not getting it. Could you please help me out, if you have the answers. Thanx Mughi

        M 1 Reply Last reply
        0
        • M Mughi

          Hi, Here is the code. FILE *fp = fopen(this->output,"w"); fprintf(fp,"8\n"); for(rc=0;rc<9;rc++) for(gc=0;gc<9;gc++) for(bc=0;bc<9;bc++) { lut[0][rc][gc][bc] = (lut[0][rc][gc][bc]>255)?255:lut[0][rc][gc][bc]; lut[1][rc][gc][bc] = (lut[1][rc][gc][bc]>255)?255:lut[1][rc][gc][bc]; lut[2][rc][gc][bc] = (lut[2][rc][gc][bc]>255)?255:lut[2][rc][gc][bc]; fprintf(fp,"%d %d %d\n",lut[0][rc][gc][bc],lut[1][rc][gc][bc],lut[2][rc][gc][bc]); } fclose(fp); When my MFC application still runs, Iam able to open the file in dos prompt, but not in any of WIN32 application or in my own MFC application. Am still not getting it. Could you please help me out, if you have the answers. Thanx Mughi

          M Offline
          M Offline
          Mughi
          wrote on last edited by
          #4

          Hi, The file was opened somewhere else (for other module) and was not closed. I had to track down the whole flow of the application and had the problem solved. Thats been a silly mistake and sorry for the inconvenience caused. Thanks for your support. Thanx Mughi

          1 Reply Last reply
          0
          • M Mughi

            Hi, I have created a MDI using MFC Application. The application is developed to process some input files and create an output file. At the end of the process, after the output file is created, iam trying to open the same. But its popping an error message saying "A sharing violation occured while accessing C:\temp\output.txt" And, iam not able to open it through any other application and the popping error message is "The document C:\temp\output.txt is being used by another application and cannot be accessed". I have properly coded on file opening and file closing. But still, iam not able to understand on why the problem occurs. Only, when i close my MFC application, iam able to access the created output file through any applicaton. Could someone, please help me, to get out of this situation. I thank in advance. Thanx Mughi Mughilan

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            close the file before reopening it


            TOXCCT >>> GEII power

            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