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. _argv[] proglems

_argv[] proglems

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
21 Posts 2 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.
  • H hlmechanic

    I have went to folder options and set .syx to open H:\copy of folder\prog.exe Now when I double click a .syx file , it opens prog.exe but I do not know how to get the information about the opening file other than to us _argv, and it gives strange results. I beleive I am missing somethin since standard programs such as notepade and others do this with no apparent problem.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #6

    Do you have a console or a Windows application? Look in the registry for your .syx extension and note what you see. How is %1 being handled?


    "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

    "Judge not by the eye but by the heart." - Native American Proverb

    H 1 Reply Last reply
    0
    • D David Crow

      Do you have a console or a Windows application? Look in the registry for your .syx extension and note what you see. How is %1 being handled?


      "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

      "Judge not by the eye but by the heart." - Native American Proverb

      H Offline
      H Offline
      hlmechanic
      wrote on last edited by
      #7

      I am curently using windows98. I have open regedit and did a search for .syx and did not find anything with %1 in it. I am afraid you may be going over my head. i.e. i'm lost.

      D 1 Reply Last reply
      0
      • H hlmechanic

        I am curently using windows98. I have open regedit and did a search for .syx and did not find anything with %1 in it. I am afraid you may be going over my head. i.e. i'm lost.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #8

        hlmechanic wrote:

        I am curently using windows98.

        Which matters not.

        hlmechanic wrote:

        I have open regedit and did a search for .syx

        It should be near the top of the HKEY_CLASSES_ROOT hive with all of the other file extension types. For example, if you look for .txt, you'll see it has a default value of txtfile. Looking further down the list for txtfile, you should find: HKEY_CLASSES_ROOT\txtfile\shell\open\command Does the same sort of thing not exist for your .syx extension?


        "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

        "Judge not by the eye but by the heart." - Native American Proverb

        H 1 Reply Last reply
        0
        • D David Crow

          hlmechanic wrote:

          I am curently using windows98.

          Which matters not.

          hlmechanic wrote:

          I have open regedit and did a search for .syx

          It should be near the top of the HKEY_CLASSES_ROOT hive with all of the other file extension types. For example, if you look for .txt, you'll see it has a default value of txtfile. Looking further down the list for txtfile, you should find: HKEY_CLASSES_ROOT\txtfile\shell\open\command Does the same sort of thing not exist for your .syx extension?


          "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

          "Judge not by the eye but by the heart." - Native American Proverb

          H Offline
          H Offline
          hlmechanic
          wrote on last edited by
          #9

          under HKEY_CLASSES_ROOT/.syx It says (default) "syx_auto_file" under HKEY_CLASSES_ROOT/syx_auto_file it says (default) SYX File SYX File does not show up anywhere else

          D 1 Reply Last reply
          0
          • H hlmechanic

            under HKEY_CLASSES_ROOT/.syx It says (default) "syx_auto_file" under HKEY_CLASSES_ROOT/syx_auto_file it says (default) SYX File SYX File does not show up anywhere else

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #10

            hlmechanic wrote:

            under HKEY_CLASSES_ROOT/syx_auto_file it says (default) SYX File

            You should have a shell key under that. In all, it should look like: HKEY_CLASSES_ROOT\syx_auto_file\shell\open\command If not, why not make the necessary changes to see if that helps.


            "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

            "Judge not by the eye but by the heart." - Native American Proverb

            H 1 Reply Last reply
            0
            • D David Crow

              hlmechanic wrote:

              under HKEY_CLASSES_ROOT/syx_auto_file it says (default) SYX File

              You should have a shell key under that. In all, it should look like: HKEY_CLASSES_ROOT\syx_auto_file\shell\open\command If not, why not make the necessary changes to see if that helps.


              "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

              "Judge not by the eye but by the heart." - Native American Proverb

              H Offline
              H Offline
              hlmechanic
              wrote on last edited by
              #11

              I must have missed the + befor the folder icon becouse there is HKEY_CLASSES_ROOT\syx_auto_file\shell\open\command and it's value is ""H:\Copy of folder\prog.exe"%1" My apoligies for missing this the first time.

              D 1 Reply Last reply
              0
              • H hlmechanic

                I must have missed the + befor the folder icon becouse there is HKEY_CLASSES_ROOT\syx_auto_file\shell\open\command and it's value is ""H:\Copy of folder\prog.exe"%1" My apoligies for missing this the first time.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #12

                This is just a guess, but those double quotes look ill-placed. It's hard to tell which are actually part of the registry's value and which you added as part of the post. I would have thought it to look something like:

                "H:\Copy of folder\prog.exe" "%1"


                "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

                "Judge not by the eye but by the heart." - Native American Proverb

                H 1 Reply Last reply
                0
                • D David Crow

                  This is just a guess, but those double quotes look ill-placed. It's hard to tell which are actually part of the registry's value and which you added as part of the post. I would have thought it to look something like:

                  "H:\Copy of folder\prog.exe" "%1"


                  "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

                  "Judge not by the eye but by the heart." - Native American Proverb

                  H Offline
                  H Offline
                  hlmechanic
                  wrote on last edited by
                  #13

                  I got it to look like you said. now when I double click a .syx file I get _argc=4 with _argv[3] as H:\copyof~2\file.syx I could use _argv[_argc-1] to get this value but I still get unexpected results from just double clicking the aplication icon in explorer window. p.s. what does the %1 do?

                  D 1 Reply Last reply
                  0
                  • H hlmechanic

                    I got it to look like you said. now when I double click a .syx file I get _argc=4 with _argv[3] as H:\copyof~2\file.syx I could use _argv[_argc-1] to get this value but I still get unexpected results from just double clicking the aplication icon in explorer window. p.s. what does the %1 do?

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #14

                    hlmechanic wrote:

                    now when I double click a .syx file I get _argc=4...

                    Which it should be 2.

                    hlmechanic wrote:

                    with _argv[3] as H:\copyof~2\file.syx

                    What is the value of _argv[0], _argv[1], and _argv[2]?

                    hlmechanic wrote:

                    p.s. what does the %1 do?

                    Nothing per se. It gets replaced by the file that was double-clicked.


                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                    "Judge not by the eye but by the heart." - Native American Proverb

                    H 1 Reply Last reply
                    0
                    • D David Crow

                      hlmechanic wrote:

                      now when I double click a .syx file I get _argc=4...

                      Which it should be 2.

                      hlmechanic wrote:

                      with _argv[3] as H:\copyof~2\file.syx

                      What is the value of _argv[0], _argv[1], and _argv[2]?

                      hlmechanic wrote:

                      p.s. what does the %1 do?

                      Nothing per se. It gets replaced by the file that was double-clicked.


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      H Offline
                      H Offline
                      hlmechanic
                      wrote on last edited by
                      #15

                      I am no longer at the same computer. now I am at a computer running windows XP. It gives me _argc=5. _argv[0] is still what is expected. The rest seem to be "H:\Copy of folder\prog.exe H:\Copy of folder\file.syx" with each _argv[] after 0 being a part of the line between spaces (except the space between the two file names). Windows seems to be trying to break the line up into arguments as a dos line would be. I was wishing there was a way to get this information that did not involve _argv[] or some way to make it give me the whole line so that I could break it up as I wanted. Also I wanted to thank you for your help.

                      D 1 Reply Last reply
                      0
                      • H hlmechanic

                        I have written a C++ program and I wish it to be able to be started by dragging a file icon onto the program icon in windows explorer. The program name is prog.exe, the file name is file.syx, they are both in folder "H:\folder". When the file is dragged onto the program icon in explorer and starts, the value of _argc=1 with _argv[0] being "H:\folder\prog.exe" and _argv[1] being "H:\folder\file.syx" as expected. I then use this information to open file.syx. However, if the program and file are moved to a folder with a space in the name such as "H:\copy of folder", then when I drag file.syx onto prog.exe I get these unexpected results. _argc=3 with _argv[0]="H:\folder\prog.exe", _argv[1]="of", _argv[2] = "folder\prog.exe H:\copyof~2\file.syx". If I just double click "H:\copy of folder\prog.exe" I get _argc=3 with _argv[0]="H:\folder\prog.exe", _argv[1]="of", _argv[2] = "folder\prog.exe ". I have tested this program on windows98 and windowsXP with the same basic results. If anybody knows how to consistently get the name of a file that is ‘dragged onto a program icon to start that program’ from inside that program then I would appreciate the help.

                        H Offline
                        H Offline
                        hlmechanic
                        wrote on last edited by
                        #16

                        I have found GetCommandLine() wich seems to be promising. When H:\copy of folder\file.syx is draged and droped onto H:\copy of folder\prog.exe then GetCommndLine() returns "H:\copy of folder\prog.exe" ":\copy of folder\file.syx" (including quote marks). If the same thing is done in H:\folder then "H:\copy of folder\prog.exe" H:\copy of folder\file.syx is given (note change in quote marks). I think I can get the filename from this. I found this from the questions and answers at the end of the folowing article Managing argc and argv[] with STL in a simple way specal thanks to DavidCrow for trying to educate me.

                        D 1 Reply Last reply
                        0
                        • H hlmechanic

                          I am no longer at the same computer. now I am at a computer running windows XP. It gives me _argc=5. _argv[0] is still what is expected. The rest seem to be "H:\Copy of folder\prog.exe H:\Copy of folder\file.syx" with each _argv[] after 0 being a part of the line between spaces (except the space between the two file names). Windows seems to be trying to break the line up into arguments as a dos line would be. I was wishing there was a way to get this information that did not involve _argv[] or some way to make it give me the whole line so that I could break it up as I wanted. Also I wanted to thank you for your help.

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #17

                          You still have not indicated whether this is a console or GUI application. That makes a ton of difference in how command-line arguments and drag/drop operations are handled.


                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                          "Judge not by the eye but by the heart." - Native American Proverb

                          1 Reply Last reply
                          0
                          • H hlmechanic

                            I have found GetCommandLine() wich seems to be promising. When H:\copy of folder\file.syx is draged and droped onto H:\copy of folder\prog.exe then GetCommndLine() returns "H:\copy of folder\prog.exe" ":\copy of folder\file.syx" (including quote marks). If the same thing is done in H:\folder then "H:\copy of folder\prog.exe" H:\copy of folder\file.syx is given (note change in quote marks). I think I can get the filename from this. I found this from the questions and answers at the end of the folowing article Managing argc and argv[] with STL in a simple way specal thanks to DavidCrow for trying to educate me.

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #18

                            If this is a GUI application, are you handling the WM_DROPFILES message?


                            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                            "Judge not by the eye but by the heart." - Native American Proverb

                            H 1 Reply Last reply
                            0
                            • D David Crow

                              If this is a GUI application, are you handling the WM_DROPFILES message?


                              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                              "Judge not by the eye but by the heart." - Native American Proverb

                              H Offline
                              H Offline
                              hlmechanic
                              wrote on last edited by
                              #19

                              This is a GUI. Written in Borland C++ 4.52 I handled WM_DROPFILES with the folowing code. void DrumWindow::EvDropFiles(TDropInfo dropInfo){ int NumFiles; char NextFile [MAX_PATH]; NumFiles = dropInfo.DragQueryFile (-1, NULL, 0 );// Get the # of files being dropped.; for (int File = 0; File < NumFiles; File++ ){ if ( dropInfo.DragQueryFile (File,NextFile,MAX_PATH ) > 0 ){// Get the next filename from the HDROP info. /////work with file name NextFile here if valid (removed to keep short) };//end if next exist };//end for each file dropInfo.DragFinish ();// Free up memory. };//end EvDropfiles

                              D 1 Reply Last reply
                              0
                              • H hlmechanic

                                This is a GUI. Written in Borland C++ 4.52 I handled WM_DROPFILES with the folowing code. void DrumWindow::EvDropFiles(TDropInfo dropInfo){ int NumFiles; char NextFile [MAX_PATH]; NumFiles = dropInfo.DragQueryFile (-1, NULL, 0 );// Get the # of files being dropped.; for (int File = 0; File < NumFiles; File++ ){ if ( dropInfo.DragQueryFile (File,NextFile,MAX_PATH ) > 0 ){// Get the next filename from the HDROP info. /////work with file name NextFile here if valid (removed to keep short) };//end if next exist };//end for each file dropInfo.DragFinish ();// Free up memory. };//end EvDropfiles

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #20

                                I'm confused. Why are you using GetCommandLine() when DragQueryFile() is how "dropped" files are retrieved?


                                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                "Judge not by the eye but by the heart." - Native American Proverb

                                H 1 Reply Last reply
                                0
                                • D David Crow

                                  I'm confused. Why are you using GetCommandLine() when DragQueryFile() is how "dropped" files are retrieved?


                                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                  "Judge not by the eye but by the heart." - Native American Proverb

                                  H Offline
                                  H Offline
                                  hlmechanic
                                  wrote on last edited by
                                  #21

                                  my wish is to find out wich file was used to start the program by dragging the icon of the file onto the unopened program icon. I would also like to be able to set the file extenshion to open the file using this program so the user can double click on a file with the right extenshion and start the program with that file loaded into it. I do not know how to make DragQueryFile() tell me wich file was used to start the program. The Drag and Drop onto the open program window works great but I have not noticed that it sends any information about a file that was draged onto the unopened program icon in windows explorer, or about wich program was double clicked to start this program. I suspect that this is because DragAcceptFiles is not called untill 'SetupWindow()' IF there is a better place to put DragAcceptFiles that would let the program find out this information it would be much easyer to do.

                                  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