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. CreateProcess lpApplicationName param

CreateProcess lpApplicationName param

Scheduled Pinned Locked Moved C / C++ / MFC
json
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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi I have a program in subdirectory folder as such c:\dira\dirb\program.exe When I do GetCurrentDirectory API I get c:\dira When Use "program.exe" as the first parm I get returned code 0 followed by file not found from GetLastError

    L J 2 Replies Last reply
    0
    • F ForNow

      Hi I have a program in subdirectory folder as such c:\dira\dirb\program.exe When I do GetCurrentDirectory API I get c:\dira When Use "program.exe" as the first parm I get returned code 0 followed by file not found from GetLastError

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Return code 0 means the command completed successfully, so calling GetLastError is not necessary, and will give you a meaningless response. My mistake.

      J 1 Reply Last reply
      0
      • F ForNow

        Hi I have a program in subdirectory folder as such c:\dira\dirb\program.exe When I do GetCurrentDirectory API I get c:\dira When Use "program.exe" as the first parm I get returned code 0 followed by file not found from GetLastError

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        Just use the full path for the lpApplicationName parameter. Avoid using partial names. When using them you have to ensure that the current working directory is set to the parent of the partial name resulting in a path containg that file. The only exception is when you know that the application is stored in one of the directories specified in the PATH environment variable. Then you can use the plain file name.

        F 1 Reply Last reply
        0
        • L Lost User

          Return code 0 means the command completed successfully, so calling GetLastError is not necessary, and will give you a meaningless response. My mistake.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          The CreateProcessA function | Microsoft Docs[^] returns a BOOL where zero indicates failure.

          L 1 Reply Last reply
          0
          • J Jochen Arndt

            The CreateProcessA function | Microsoft Docs[^] returns a BOOL where zero indicates failure.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Sorry, I misread something somewhere.

            1 Reply Last reply
            0
            • J Jochen Arndt

              Just use the full path for the lpApplicationName parameter. Avoid using partial names. When using them you have to ensure that the current working directory is set to the parent of the partial name resulting in a path containg that file. The only exception is when you know that the application is stored in one of the directories specified in the PATH environment variable. Then you can use the plain file name.

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              The problem with using the full path name if my .exe is stored in c:\dira\dirb GetCurrentDirectory only returns c:\dira my module is stored in the current directory Thanks

              J 1 Reply Last reply
              0
              • F ForNow

                The problem with using the full path name if my .exe is stored in c:\dira\dirb GetCurrentDirectory only returns c:\dira my module is stored in the current directory Thanks

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                You have to know (and usually will know) where the file is stored. Where is the problem using the full path? GetCurrentDirectory() returns the actual working directory of the session. It is not related in any way to the application calling that function (besides the application has set the working directory explicitly). Again: Use full pathes. If necessary create them dynamically during runtime. But never expect the current working directory to be a specific one if you have not set it. But when setting it, you can also create full pathes instead. If you need to know where the application actually executed is stored, access the first command line parameter argv[0] in your main() function. That contains the full path of the executable. Or use the GetModuleFileName function (Windows)[^] with the first parameter set to NULL. With both methods you can extract the path which can be for example used to access other files known to exist in the same directory or a sub directory.

                F 1 Reply Last reply
                0
                • J Jochen Arndt

                  You have to know (and usually will know) where the file is stored. Where is the problem using the full path? GetCurrentDirectory() returns the actual working directory of the session. It is not related in any way to the application calling that function (besides the application has set the working directory explicitly). Again: Use full pathes. If necessary create them dynamically during runtime. But never expect the current working directory to be a specific one if you have not set it. But when setting it, you can also create full pathes instead. If you need to know where the application actually executed is stored, access the first command line parameter argv[0] in your main() function. That contains the full path of the executable. Or use the GetModuleFileName function (Windows)[^] with the first parameter set to NULL. With both methods you can extract the path which can be for example used to access other files known to exist in the same directory or a sub directory.

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #8

                  This helps I’ll look into this thanks

                  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