0

When you right click on a program in windows(such as starcraft.exe) and look at its properties there is a text field called "target" which contains the full path of the binary. I have seen programs able to parse flags added to the target such as "C:\programfiles\myprogram\myprogram.exe -x 1280 -y 360" and the program would start up in the specified resolution. My question is how to read those arguments, if it is done by argv[] please just inform me of my stupidity.

C++ is the language, VS express 2012 desktop is the environment.

  • Yes, those are normal command line arguments. If, on the other hand, you're after retrieving the command line string from the shortcut, there's a shell interface that you can use for that. – chris May 30 '13 at 08:08

2 Answers2

1

you receive those parameters when calling executable main method int main(int argc, char* argv[]) as argc (count) and argv[] parameters all you have to do is just parse them

here is an example How to parse command line parameters

makc
  • 2,569
  • 1
  • 18
  • 28
0

You'll want to avoid comparisons between char* and string literals without strncmp. Remember that argc is the the argument count (including the program name).

argv is an array of C strings specifying the arguments (first being the program name as invoked).

In this case, you're usually best off using a library, like getopt. This will make interleaved options, long options, and arguments much more sane to manage (assuming order between options and arguments is largely unimportant).

Taywee
  • 1,313
  • 11
  • 17