C ++ WIN API: When creating a child process using CreateProcess, do I need the input parameters to have global lifetime?

I am really new to both C ++ and the Windows API. Today, the question suddenly arises to me whether I need to maintain a long service life of the input parameters CreateProcess. According to 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
);

for example, LPSTARTUPINFO lpStartupInfoa pointer pointing to a STARTUPINFO structure.

I am wondering if you need to keep the structure after it CreateProcessreturns. In addition, other Windows API functions have similar input parameters that are entered as a pointer, I don’t know if I need to save the objects pointed to by input pointers after returning the API functions.

WaitForSingleObject , , CreateProcess. CreateProcess "ExecuteProcess". CreateProcess ExecuteProcess, , , ExecuteProcess.

MSDN , , CreateProcess . CreateProcess CreateChildProcess, "CreateChildProcess" WaitForSingleObject .

+4
3

. . , .

+5

, API Win32 , . , . , , , - , , . , , .

, , CreateProcess , CreateProcess. , , , CreateProcess , , . - , .

, , Win32.

+4

, .

, , , Unicode- .

There are also some undocumented functions in which you may need to store the actual arguments until the new process terminates, or at least until it uses the data. I do not remember exactly. But this is not a problem for normal use.

-1
source

Source: https://habr.com/ru/post/1544136/


All Articles