int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
请问如何传递参数
比如程序是aaa.exe我这样执行aaa.exe 111 222请问在程序里我如何得到111和222

解决方案 »

  1.   

    GetCommandLine()或者lpCmdLine参数都能获得整个命令行,包括exe文件本身,要得到参数,再调用CommandLineToArgvW即可得到一个字符串指针数组
      

  2.   

    一般是用GetCommandLine来获取参数,直接调用LPTSTR   str=GetCommandLine(); 就行了,不过返回值中是包含可行文件名的
      

  3.   


    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    CWinApp::ParseCommandLine()试试
      

  4.   

    aaa.exe 111 222
    当你获得到参数 【111 222】 时,你需要自己解释,根据空格把两部分分开。
      

  5.   

    __argc表示参数个数,__argv[]是参数数组。例如aaa.exe 111 222:
    __argc是3;
    __argv[0]是"aaa.exe";
    __argv[1]是"111";
    __argv[2]是"222"。
      

  6.   

       LPWSTR *szArglist;
       int nArgs;
       int i;   szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
       if( NULL == szArglist )
       {
          wprintf(L"CommandLineToArgvW failed\n");
          return 0;
       }
       else for( i=0; i<nArgs; i++) printf("%d: %ws\n", i, szArglist[i]);// Free memory allocated for CommandLineToArgvW arguments.   LocalFree(szArglist);
      

  7.   


    int a, b;
    scanf(lpCmdLine, &a, &b); // a = 111 b = 222;
      

  8.   


    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);