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. ::ShellExecute - Problem passing arguments

::ShellExecute - Problem passing arguments

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
13 Posts 6 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.
  • P PankajB

    Hi there. I have an Console based Exe (ABC.exe) that takes some parameters. Now, I want to call this Exe from some other application and want to pass the paremeters as required. Problems: 1. I am calling this exe as below

    HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW);

    ABC.exe application got launched but text "Hello" never got displayed on the console. 2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that. Help will be really appretiated. Thanks PanB

    R Offline
    R Offline
    Rajesh R Subramanian
    wrote on last edited by
    #2

    PankajB wrote:

    ABC.exe application got launched but text "Hello" never got displayed on the console.

    What is the target application doing with the parameters passed on to it? Is there any code for displaying it or not? :rolleyes:

    PankajB wrote:

    2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that.

    You can pass the CString variable as the fourth parameter as it is, because ShellExecute is expecting an LPCTSTR there and CString will be automatically casted there.

    It is a crappy thing, but it's life -^ Carlo Pallini

    P 1 Reply Last reply
    0
    • R Rajesh R Subramanian

      PankajB wrote:

      ABC.exe application got launched but text "Hello" never got displayed on the console.

      What is the target application doing with the parameters passed on to it? Is there any code for displaying it or not? :rolleyes:

      PankajB wrote:

      2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that.

      You can pass the CString variable as the fourth parameter as it is, because ShellExecute is expecting an LPCTSTR there and CString will be automatically casted there.

      It is a crappy thing, but it's life -^ Carlo Pallini

      P Offline
      P Offline
      PankajB
      wrote on last edited by
      #3

      I am basically passing a path to a file. Target application just check whether file exists, if does not then create that file.

      R 1 Reply Last reply
      0
      • P PankajB

        Hi there. I have an Console based Exe (ABC.exe) that takes some parameters. Now, I want to call this Exe from some other application and want to pass the paremeters as required. Problems: 1. I am calling this exe as below

        HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW);

        ABC.exe application got launched but text "Hello" never got displayed on the console. 2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that. Help will be really appretiated. Thanks PanB

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #4

        PankajB wrote:

        ABC.exe application got launched but text "Hello" never got displayed on the console.

        Why would it be displayed on the console ? Are you retrieving it in the code of your application and prining the argument ? If yes, it's the argument at index 1, and not 0 that you have to use (the first argument is always the path to your application).

        PankajB wrote:

        In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that.

        Just pass the CString object.

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        1 Reply Last reply
        0
        • P PankajB

          I am basically passing a path to a file. Target application just check whether file exists, if does not then create that file.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #5

          PankajB wrote:

          Target application just check whether file exists, if does not then create that file.

          You can as well create the file from the calling application as well. Why are you needing to have an executable solely for this? Or is there anything else? If the file copying takes too long and that leaves you with a frozen UI, just spawn a thread. Can't you? You haven't answered my question: Is the target application handling the command line passed on to it? Without that being done, how will it display the command line?

          It is a crappy thing, but it's life -^ Carlo Pallini

          1 Reply Last reply
          0
          • P PankajB

            Hi there. I have an Console based Exe (ABC.exe) that takes some parameters. Now, I want to call this Exe from some other application and want to pass the paremeters as required. Problems: 1. I am calling this exe as below

            HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW);

            ABC.exe application got launched but text "Hello" never got displayed on the console. 2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that. Help will be really appretiated. Thanks PanB

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

            Does your ABC.exe application correctly print it's first argument if launched by command line? :)

            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.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • P PankajB

              Hi there. I have an Console based Exe (ABC.exe) that takes some parameters. Now, I want to call this Exe from some other application and want to pass the paremeters as required. Problems: 1. I am calling this exe as below

              HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW);

              ABC.exe application got launched but text "Hello" never got displayed on the console. 2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that. Help will be really appretiated. Thanks PanB

              P Offline
              P Offline
              PankajB
              wrote on last edited by
              #7

              Let me provide few details... 1. Lets say ABC.exe just cout the text provided as an argument. 2. If I launch ABC.exe from console, >ABC.exe Hello, it prints out Hello on the Screen. 3. if I call the same application like HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW); ...it does not Just FYI, ABC.exe is a Console based Application

              M R CPalliniC 3 Replies Last reply
              0
              • P PankajB

                Let me provide few details... 1. Lets say ABC.exe just cout the text provided as an argument. 2. If I launch ABC.exe from console, >ABC.exe Hello, it prints out Hello on the Screen. 3. if I call the same application like HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW); ...it does not Just FYI, ABC.exe is a Console based Application

                M Offline
                M Offline
                Michael Schubert
                wrote on last edited by
                #8

                Is the calling application also a console app? If not, does it open a new console window?

                1 Reply Last reply
                0
                • P PankajB

                  Let me provide few details... 1. Lets say ABC.exe just cout the text provided as an argument. 2. If I launch ABC.exe from console, >ABC.exe Hello, it prints out Hello on the Screen. 3. if I call the same application like HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW); ...it does not Just FYI, ABC.exe is a Console based Application

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #9

                  You must show us the target application's code, where you've handled the command line passed on to it.

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  1 Reply Last reply
                  0
                  • P PankajB

                    Let me provide few details... 1. Lets say ABC.exe just cout the text provided as an argument. 2. If I launch ABC.exe from console, >ABC.exe Hello, it prints out Hello on the Screen. 3. if I call the same application like HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW); ...it does not Just FYI, ABC.exe is a Console based Application

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

                    HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\carlo.pallini\\ABC.exe", L"Hello", NULL, SW_SHOW);

                    works fine with my ABC.exe app... :rolleyes:

                    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.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    In testa che avete, signor di Ceprano?

                    M 1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\carlo.pallini\\ABC.exe", L"Hello", NULL, SW_SHOW);

                      works fine with my ABC.exe app... :rolleyes:

                      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.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      M Offline
                      M Offline
                      Michael Schubert
                      wrote on last edited by
                      #11

                      CPallini wrote:

                      works fine with my ABC.exe app...

                      You must have the final release. I tried it with Beta 3 of abc.exe and the output was "Get lost" instead of "Hello"...

                      CPalliniC 1 Reply Last reply
                      0
                      • M Michael Schubert

                        CPallini wrote:

                        works fine with my ABC.exe app...

                        You must have the final release. I tried it with Beta 3 of abc.exe and the output was "Get lost" instead of "Hello"...

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

                        :-D

                        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.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        In testa che avete, signor di Ceprano?

                        1 Reply Last reply
                        0
                        • P PankajB

                          Hi there. I have an Console based Exe (ABC.exe) that takes some parameters. Now, I want to call this Exe from some other application and want to pass the paremeters as required. Problems: 1. I am calling this exe as below

                          HINSTANCE hInst = ::ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\pankaj.bhalla\\Desktop\\ABC.exe", L"Hello", NULL, SW_SHOW);

                          ABC.exe application got launched but text "Hello" never got displayed on the console. 2. In place of this hardcoded text i.e., "Hello", incase I want to send some text stored in CString type variable then how can I do that. Help will be really appretiated. Thanks PanB

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

                          PankajB wrote:

                          ABC.exe application got launched but text "Hello" never got displayed on the console.

                          Does the console window open at all?

                          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          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