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. WinExec("Notepad.exe " +fileName,SW_SHOW doesn't work )

WinExec("Notepad.exe " +fileName,SW_SHOW doesn't work )

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • Q Offline
    Q Offline
    Qadddd
    wrote on last edited by
    #1

    fileName is the name of the file I just created some lines above the WinExec Command. I have an Object f of CStdioFile type, I open it in creation mode, I write in it with f.WriteString and then close it. I want to launch a Notepad to preview its content, Notepad starts but the content of file is not displayed, if I click on File>Open>file name, it works and content is displayed . Format of WinExec and content of fileName are correct because using the same instruction a the beginning of my routine (before open/write/close), I can start a notepad displaying the file previously created. It is just like the file is not yet available for notepad even if a close is done ...!? Any help is welcome DD

    A Q 2 Replies Last reply
    0
    • Q Qadddd

      fileName is the name of the file I just created some lines above the WinExec Command. I have an Object f of CStdioFile type, I open it in creation mode, I write in it with f.WriteString and then close it. I want to launch a Notepad to preview its content, Notepad starts but the content of file is not displayed, if I click on File>Open>file name, it works and content is displayed . Format of WinExec and content of fileName are correct because using the same instruction a the beginning of my routine (before open/write/close), I can start a notepad displaying the file previously created. It is just like the file is not yet available for notepad even if a close is done ...!? Any help is welcome DD

      A Offline
      A Offline
      adamUK
      wrote on last edited by
      #2

      Couldn't you open the file with nOpenFlags = CFile::shareDenyNone so that other apps have access to your file even when you have it open within your app? Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

      1 Reply Last reply
      0
      • Q Qadddd

        fileName is the name of the file I just created some lines above the WinExec Command. I have an Object f of CStdioFile type, I open it in creation mode, I write in it with f.WriteString and then close it. I want to launch a Notepad to preview its content, Notepad starts but the content of file is not displayed, if I click on File>Open>file name, it works and content is displayed . Format of WinExec and content of fileName are correct because using the same instruction a the beginning of my routine (before open/write/close), I can start a notepad displaying the file previously created. It is just like the file is not yet available for notepad even if a close is done ...!? Any help is welcome DD

        Q Offline
        Q Offline
        Qadddd
        wrote on last edited by
        #3

        I would like to precise that I have tried to open my file with CFile::shareDenyNone because I thought problem was coming from a conflict but result was the same ...

        A 1 Reply Last reply
        0
        • Q Qadddd

          I would like to precise that I have tried to open my file with CFile::shareDenyNone because I thought problem was coming from a conflict but result was the same ...

          A Offline
          A Offline
          adamUK
          wrote on last edited by
          #4

          DD, Are you opening the file with just CFile::modeCreate? I have just put together an app to try to recreate your problem on VC6. Everything works just fine but you can't write to your file if you open in CFile::modeCreate only. It has to be CFile::modeCreate+CFile::modeWrite. e.g. CStdioFile file; file.Open("c:\\filetest.txt", CFile::modeCreate+CFile::modeWrite+CFile::shareExclusive,NULL); file.SeekToEnd(); file.WriteString("this is written\n"); file.Close(); WinExec("c:\\WINNT\\notepad.exe c:\\FileTest.txt",SW_SHOW); works fine and dandy. CStdioFile file; file.Open("c:\\filetest.txt",CFile::modeCreate+CFile::shareExclusive,NULL); file.SeekToEnd(); file.WriteString("this is written\n"); file.Close(); WinExec("c:\\WINNT\\notepad.exe c:\\FileTest.txt",SW_SHOW); fails at WriteString() and never gets to WinExec. If you post the code that's causing you a prob then perhaps we could have a look? hope this helps Adam. P.S. would recommend using ShellExecuteEx rather than WinExec as you can get a handle to Notepad to see when it has terminated. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

          C 1 Reply Last reply
          0
          • A adamUK

            DD, Are you opening the file with just CFile::modeCreate? I have just put together an app to try to recreate your problem on VC6. Everything works just fine but you can't write to your file if you open in CFile::modeCreate only. It has to be CFile::modeCreate+CFile::modeWrite. e.g. CStdioFile file; file.Open("c:\\filetest.txt", CFile::modeCreate+CFile::modeWrite+CFile::shareExclusive,NULL); file.SeekToEnd(); file.WriteString("this is written\n"); file.Close(); WinExec("c:\\WINNT\\notepad.exe c:\\FileTest.txt",SW_SHOW); works fine and dandy. CStdioFile file; file.Open("c:\\filetest.txt",CFile::modeCreate+CFile::shareExclusive,NULL); file.SeekToEnd(); file.WriteString("this is written\n"); file.Close(); WinExec("c:\\WINNT\\notepad.exe c:\\FileTest.txt",SW_SHOW); fails at WriteString() and never gets to WinExec. If you post the code that's causing you a prob then perhaps we could have a look? hope this helps Adam. P.S. would recommend using ShellExecuteEx rather than WinExec as you can get a handle to Notepad to see when it has terminated. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

            C Offline
            C Offline
            Carlos Antollini
            wrote on last edited by
            #5

            You don't need to use CFile::SeekToEnd When you open the file you are creting the file, id for that you are in the end of the file.... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

            A 1 Reply Last reply
            0
            • C Carlos Antollini

              You don't need to use CFile::SeekToEnd When you open the file you are creting the file, id for that you are in the end of the file.... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

              A Offline
              A Offline
              adamUK
              wrote on last edited by
              #6

              Cheers pal.. I was testing the code out using modeRead, modeWrite and some other combinations to see if I could recreate Qadddd's problem. I kinda left the SeekToEnd() in there by accident. Cheers anyway! :) "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

              Q 1 Reply Last reply
              0
              • A adamUK

                Cheers pal.. I was testing the code out using modeRead, modeWrite and some other combinations to see if I could recreate Qadddd's problem. I kinda left the SeekToEnd() in there by accident. Cheers anyway! :) "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

                Q Offline
                Q Offline
                Qadddd
                wrote on last edited by
                #7

                The code looks like this (I am at work, not at home and doesn't have my source code near me) =========================== CStdioFile f; char pFileName[] = "myfile.txt"; char buff[] = "test string"; f.Open( pFileName, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite | CFile::typeText); // tested with CFile::shareDenyNone instead of CFile::shareDenyWrite but it doesn't correct f.WriteString(buff); // and more writings f.Close; // supposed to close file and make it available WinExec("Notepad.exe myfile.txt",SW_SHOW) =========================== The same WinExec instruction put at the beginning of my routine works fine if I launch it a second time and the content of the file created during the 1st pass is correctly displayed ... Hope it is a little bit more clear....

                A 1 Reply Last reply
                0
                • Q Qadddd

                  The code looks like this (I am at work, not at home and doesn't have my source code near me) =========================== CStdioFile f; char pFileName[] = "myfile.txt"; char buff[] = "test string"; f.Open( pFileName, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite | CFile::typeText); // tested with CFile::shareDenyNone instead of CFile::shareDenyWrite but it doesn't correct f.WriteString(buff); // and more writings f.Close; // supposed to close file and make it available WinExec("Notepad.exe myfile.txt",SW_SHOW) =========================== The same WinExec instruction put at the beginning of my routine works fine if I launch it a second time and the content of the file created during the 1st pass is correctly displayed ... Hope it is a little bit more clear....

                  A Offline
                  A Offline
                  adamUK
                  wrote on last edited by
                  #8

                  Hmm.. Apart from changing f.Close; to f.Close(); and setting WinExec("Notepad.exe myfile.txt",SW_SHOW) to WinExec("c:\\WINNT\\Notepad.exe myfile.txt",SW_SHOW); it all works okay. It looks like one of those annoying ones that works on one PC and not the other! :( I don't know if it is worth setting up a timer to send a WM_TIMER message and handling the message to open Notepad after about a quarter of a second or so and seeing what happens? hope this helps. Sounds very perplexing! :eek: Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

                  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