主进程示例:
STARTUPINFOA si; si.cb = sizeof(STARTUPINFO);//必须初始化si si.lpReserved = NULL; si.lpDesktop = NULL; si.lpTitle = NULL; si.dwFlags = 0; si.cbReserved2 = 0; si.lpReserved2 = NULL; PROCESS_INFORMATION pi;
if(!CreateProcess("D://Demo//testcmdpara.exe","cmdline",NULL,NULL, FALSE, 0, NULL, NULL, &si, &pi)) {/创建失败
CString info; info.Format("LastError=%d",GetLastError(););
MessageBox(info,"Tip"); }
子进程示例:
//在app,InitInstance增加处理命令行参数 DWORD Argc; LPTSTR * Argv; #ifdef UNICODE Argv = CommandLineToArgvW(GetCommandLineW(), &Argc );#else Argc = (DWORD) __argc; Argv = __argv;#endif if(Argc >0) { if(*Argv[0] == _T(cmdline))
设置相应参数
else
设置相应参数
}