1

Consider the command line argument:

D:\work\test.exe -a -p

My C++ application's main() receives the arguments as follows:

  1. Windows 10

    argc = 3  
    
    argv[0] = "D:\work\test.exe"
    
    argv[1] = "-a" 
    
    argv[2] = "-p"
    
  2. Windows XP

    argv = 3    
    
    argv[0] = "test.exe"
    
    argv[1] = "-a"   
    
    argv[2] = "-p"
    

The argument argv[0] is being parsed differently. My application needs them to be same.
Is there any way to get the entire path in Windows XP as well?
I have tried both main and winmain and the result is the same.

Akash Jain
  • 23
  • 6
  • *Why*? What is the *real* problem you need to solve? Please read about [the XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Some programmer dude Jan 03 '19 at 10:10
  • XP, like the OS that is deprecated and unsecure for years now? – Matthieu Brucher Jan 03 '19 at 10:17
  • @MatthieuBrucher Unfortunately there's still quite a few projects in production using Windows XP. I'm working on one myself (Windows XP Embedded), but fortunately we're working on migrating it to Windows 10 IoT currently. – Some programmer dude Jan 03 '19 at 10:29
  • @Someprogrammerdude wow... good luck :/ Was XP Embedded also deprecated with XP, or was its lifetime extended? – Matthieu Brucher Jan 03 '19 at 10:30
  • 1
    @MatthieuBrucher It's also end-of-life since many years. That's not the worst part through, The system (even on Windows 10) have to be built on Borland C++ Builder 6 which is almost as old as Windows XP! :P – Some programmer dude Jan 03 '19 at 10:32
  • 1
    I would argue that if your program _requires_ any particular form for `argv[0]` then it is broken! – Lightness Races in Orbit Jan 03 '19 at 11:21
  • To be fair, guys, XP still works just great. It's not _that_ old in the grand scheme of things. Just don't plug it into the internet! But there are plenty of airgapped use cases, and migration in enterprise is not always trivial/necessary. – Lightness Races in Orbit Jan 03 '19 at 11:21

1 Answers1

0

You can determine the full path of the application's .exe file like this:

WCHAR *path = new WCHAR [32768]; // allow for long path names on Win 10
GetModuleFileNameW (NULL, path, 32768);
...
delete [] path;

Documentation

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48