I want to convert WinMain
's cmdLine
argument to argc
and argv
so I can use the argument parsing function I wrote for console applications.
This would be trivial except that I want to support "quotes" too. For example:
test.exe test1 test2 "testing testing"
should be
argv[0] = "test.exe"; argv[1] = "test1"; argv[2] = "test2"; argv[3] = "testing testing";
I realize that cmdLine doesn't have the program name (the argv[0]); this doesn't matter I can use a dummy value.
I was thinking of doing it with a regex, (("[^"]+")\s+)|(([^\s]+)\s*)
I'm not sure how well it would work though.. Probably not very well? Is there any function to do that in the windows api? Thanks
Each argument on the command line is separated by one or more spaces, and the operating system places each argument directly into its own null-terminated string. The second parameter passed to main() is an array of pointers to the character strings containing each argument (char *argv[]).
argv[1] is the first command-line argument. The last argument from the command line is argv[argc - 1] , and argv[argc] is always NULL.
argv(ARGument Vector) is array of character pointers listing all the arguments. If argc is greater than zero,the array elements from argv[0] to argv[argc-1] will contain pointers to strings.
The commandLine property of an Activity specifies what executable should be run on the Design Automation server and what arguments should be passed to it. Some of the command line parameters, such as $(appbundles[]), will be interpreted before calling the executable - see Command Lines.
If you are using Microsoft compiler, there are public symbols __argc
, __argv
and __wargv
defined in stdlib.h
. This also applies to MinGW that uses Microsoft runtime libraries.
CommandLineToArgvW looks like it would be helpful here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With