我对C++和Windows API都很陌生.今天突然想到我是否需要保持长寿命的输入参数CreateProcess.根据MSDN:
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
Run Code Online (Sandbox Code Playgroud)
例如,LPSTARTUPINFO lpStartupInfo指针指向STARTUPINFO结构.
我想知道我是否需要在CreateProcess返回后保持结构存活.另外,在其他Windows API函数中,有类似的输入参数输入作为指针,我不知道在API函数返回后是否需要保持输入指针指向的那些对象.
我不想等待使用WaitForSingleObject,或者至少不等待CreateProcess.CreateProcess包含在我的另一个名为'ExecuteProcess'的函数中.后CreateProcess返回,ExecuteProcess也返回和所有的栈上定义的输入参数将被破坏时ExecuteProcess的回报.
MSDN 创建具有重定向输入和输出的子进程的示例似乎以CreateProcess类似于我的方式使用.CreateProcess在函数中调用CreateChildProcess,所有输入参数都在'CreateChildProcess'的堆栈上定义,WaitForSingleObject也不使用.