有时启动同一个应用需要执行不同的行为时,可以在启动时带上参数,应用程序根据参数区分。具体实现如下:
应用1:
CreateProcessW( L"test2.exe", // No module name (use command line).
L"MyTest2Process", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
在应用2的主函数如WinMain中调用GetCommandLine()即可获取应用1设置的启动命令(“MyTest2Process”)。
就那么简单!