Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking down WinMain's cmdLine in old style main()'s arguments

Tags:

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

like image 475
uu. Avatar asked Feb 27 '10 05:02

uu.


People also ask

How are command line arguments separated?

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[]).

What is the first argument in command line arguments?

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.

What Argy means in command line argument?

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.

What is the handle command line arguments?

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.


2 Answers

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.

like image 110
Denis K Avatar answered Sep 27 '22 22:09

Denis K


CommandLineToArgvW looks like it would be helpful here.

like image 28
sean e Avatar answered Sep 27 '22 22:09

sean e