开发者

c++ Start process with argument

i know how to Start process with argument开发者_JAVA技巧 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


There are two choices, depending on what kind of program you are building.

  • If your program is a console mode program, use argc and argv parameters passed to your main().
  • If your program is a GUI mode program, use the pCmdLine parameter passed to your WinMain().

In either case, you can always use GetCommandLine().


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]);
}


#include <stdlib.h>
...
system("IExplore.exe google.com");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜