CreateProcess这个函数可以创建或者打开一个进程。
打开一个已知路径的进程,如notepad.exe,这种方法很直观,没什么好疑惑的。
疑惑的是创建新的进程。由于创建新进程的时候,可以为进程指定命令行参数,那么我的疑问是,这个新进程到底是怎么回事?事先有程序对应着这个新进程,然后这个程序的winmain中处理这些命令行参数么?

解决方案 »

  1.   

    lpCmdLine 
    [in] Pointer to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function. The name of the executable in the command line that the operating system provides to a process is not necessarily identical to that in the command line that the calling process gives to the CreateProcess function. The operating system may prepend a fully qualified path to an executable name that is provided without a fully qualified path.
      

  2.   

    原则上CreateProcess每次都创建一个新的进程。可以带一些commandline.如果你要求只需要一个实例,必须在进程的InitInstance中处理,当该进程存在时,将其commaline传递给其前一个已经启动的进程。
    http://blog.csdn.net/na_he/archive/2008/05/26/2482657.aspx
      

  3.   

    楼上两位还没有明白我的问题。比如说我写了一个程序,这个程序中有段代码是用CreateProcess生成一个新进程,注意此时CreateProcess的第一个参数为NULL,这个函数的第二个参数就是给新进程传递命令行参数的,假设我传了个字符串“123”。现在,我程序写完了,运行,这样得到一个进程,由于我写的那些代码,这个进程会生成一个新的进程,我现在想问的是这个新进程到底是什么样子呢?它如何去接受我传的命令行参数“123”呢?
      

  4.   

    你根本就没有理解CreateProcess这个API的参数,而且你也没有实验。
    你仔细看一下MSDN:
    If lpApplicationName is NULL, the first white-space – delimited token of the command line specifies the module name. 
    当第一个参数为NULL时,第二个参数中必须要包含一个EXE路径才行,所以你可以这样写:
    CreateProcess(NULL, "C:\\Program Files\\MyApp.exe -123", ...)才行,如果前面没有EXE的文件名,这个函数根本就不可能成功。
      

  5.   

    CreateProcess这个函数可以创建或者打开一个进程。
    ==========
    这句话同样不对,CreateProcess的功能就是创建一个新的进程,并不是打开一个进程。
      

  6.   

    打开一个已知路径的进程,如notepad.exe,这种方法很直观,没什么好疑惑的。这个说法就很奇怪,什么叫打开一个已知路径的进程。notepad.exe这个叫可执行文件,不叫进程。进程是个动态概念,文件是个死东西。lz基础知识欠缺太多了。。好好补习,不要好高骛远。