谁能介绍一下VC中命令行参数如何实现?
在Project->settings->debug选项卡->Program arguments中可以设置命令行参数,
但是设置之后如何在程序中引用这两个参数呢?
还有就是,当VC编写的程序正在运行时,执行带有参数的命令行,有什么消息产生,如何把参数传递给程序?

解决方案 »

  1.   

    #include <windows.h>
    #include <stdio.h>
    #include <shellapi.h>int __cdecl main(int argc, char * argv[])
    {
       LPWSTR *szArglist;
       DWORD nArgs;
       int i;   szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
       if( NULL == szArglist )
       {
          wprintf(L"CommandLineToArgvW failed\n");
          return 0;
       }
       else for( i=0; i<=argc; i++) printf("%ws\n", szArglist[i]);// Free memory allocated for CommandLineToArgvW arguments.   GlobalFree(szArglist);   return(1);
    }
      

  2.   

    当该程序已经在运行中的时候,使用待参数的命令行,该程序如何能够读的参数?有没有Windows消息可以利用?
      

  3.   

    modena说的是能够启动两个进程的程序,如果是只能启动一个进程的程序呢?比如金山词霸就只能够启动一个进程。对于这种程序,如何在进程已经运行时,通过命令行传递参数?