CreateProcess这个函数可以创建或者打开一个进程。
打开一个已知路径的进程,如notepad.exe,这种方法很直观,没什么好疑惑的。
疑惑的是创建新的进程。由于创建新进程的时候,可以为进程指定命令行参数,那么我的疑问是,这个新进程到底是怎么回事?事先有程序对应着这个新进程,然后这个程序的winmain中处理这些命令行参数么?
打开一个已知路径的进程,如notepad.exe,这种方法很直观,没什么好疑惑的。
疑惑的是创建新的进程。由于创建新进程的时候,可以为进程指定命令行参数,那么我的疑问是,这个新进程到底是怎么回事?事先有程序对应着这个新进程,然后这个程序的winmain中处理这些命令行参数么?
[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.
http://blog.csdn.net/na_he/archive/2008/05/26/2482657.aspx
你仔细看一下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的文件名,这个函数根本就不可能成功。
==========
这句话同样不对,CreateProcess的功能就是创建一个新的进程,并不是打开一个进程。