i know how to Start process with argument but im trying to create a program that uses this arguments. for example IE8 uses Process::Start( "IExplore.exe","google.com"); as a argument to open new window with url google.com. i want my program to use the argument are send it but i don't know how to get the the argument. like Process::Start( "myprogram.exe","TURE"); i want my program to get the ture thanks in advance Rami
+4
A:
There are two choices, depending on what kind of program you are building.
- If your program is a console mode program, use
argc
andargv
parameters passed to yourmain()
. - If your program is a GUI mode program, use the
pCmdLine
parameter passed to yourWinMain()
.
In either case, you can always use GetCommandLine()
.
Greg Hewgill
2010-08-08 20:56:36
GetCommandLine() is windows-specific though and not portable, so using argc/argv is usually to be preferred.
Frank
2010-08-08 21:23:33
That's correct. I thought it was pretty clear that the OP is using Windows.
Greg Hewgill
2010-08-08 21:38:53
i should go with the second choice right?
Ramiz Toma
2010-08-08 22:58:01
+1
A:
Assuming you write your entry point something like this:
int main(int argc, char* argv[])
Then argc
is the number of arguments used to invoke your program and argv
are the actual arguments.
Try it out:
#include <cstdio>
int main(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
printf("%s\n", argv[i]);
}
Travis Gockel
2010-08-08 20:59:41
If you're using the Windows entry point: `int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)`, then `lpCmdLine` is the command line and `nCmdShow` is the number of arguments.
Travis Gockel
2010-08-09 02:08:07