Note that there are some explanatory texts on larger screens.

plurals
  1. POCan separate calls two CreateProcess() share the same startup and process info?
    primarykey
    data
    text
    <p>if I am using <code>CreateProcess()</code> multiple times, is okay to share the <code>PROCESS_INFORMATION</code> and <code>STARTUPINFO</code> variables? Or is it really bad practice? I've read quite a bit of documentation, but I can't find any examples about handling <code>CreateProcess()</code> calls more than once.</p> <p>As an example, say I have the fake function below:</p> <pre><code> int SampleClass::sampleFn1(){ //Variables STARTUPINFOW siStartInfo; PROCESS_INFORMATION piProcInfo; memset(&amp;siStartInfo, 0, sizeof(siStartInfo)); memset(&amp;piProcInfo, 0, sizeof(piProcInfo)); siStartInfo.cb = sizeof(siStartInfo); //let us assume cmdPath = cmd.exe directory, and cmdTxtPtr has correct text if(!CreateProcess(cmdPath, cmdTxtPtr, NULL, NULL, false, 0, NULL, NULL, &amp;siStartInfo, &amp;piProcInfo)){ return 1; //failed at step 1 } if(!CreateProcess(cmdPath,_T("/C ant debug"),NULL,NULL,false,0,NULL, (LPCTSTR)directory,&amp;siStartInfo,&amp;piProcInfo)){ return 2; //failed at debug } WaitForSingleObject(piProcInfo.hProcess,10000); result = GetExitCodeProcess(piProcInfo.hProcess,&amp;exitCode); CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); return 0;//finished } </code></pre> <p>A similar function happens to work in my program, but I'd like to make it as safe as possible. </p> <p>Or... Should I do something like the code below instead:</p> <pre><code> int SampleClass::sampleFn2(){ //Variables STARTUPINFOW siStartInfo; PROCESS_INFORMATION piProcInfo; memset(&amp;siStartInfo, 0, sizeof(siStartInfo)); memset(&amp;piProcInfo, 0, sizeof(piProcInfo)); siStartInfo.cb = sizeof(siStartInfo); //let us assume cmdPath = cmd.exe directory, and cmdTxtPtr has correct text if(!CreateProcess(cmdPath, cmdTxtPtr, NULL, NULL, false, 0, NULL, NULL, &amp;siStartInfo, &amp;piProcInfo)){ return 1; //failed at update project } WaitForSingleObject(piProcInfo.hProcess,10000); result = GetExitCodeProcess(piProcInfo.hProcess,&amp;exitCode); CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); memset(&amp;siStartInfo, 0, sizeof(siStartInfo)); memset(&amp;piProcInfo, 0, sizeof(piProcInfo)); siStartInfo.cb = sizeof(siStartInfo); if(!CreateProcess(cmdPath,_T("/C ant debug"),NULL,NULL, false,0,NULL,(LPCTSTR)directory,&amp;siStartInfo,&amp;piProcInfo)){ return 2; //failed at debug } WaitForSingleObject(piProcInfo.hProcess,10000); result = GetExitCodeProcess(piProcInfo.hProcess,&amp;exitCode); CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); return 0;//finished } </code></pre> <p>Or do they both being handled poorly? Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload