- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我对 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
);
例如,LPSTARTUPINFO lpStartupInfo
是指向 STARTUPINFO 结构的指针。
我想知道在 CreateProcess
返回后是否需要让结构保持事件状态。另外,在其他的Windows API函数中,也有类似的输入参数作为指针输入,不知道API函数返回后是否需要让输入指针指向的那些对象保持存活。
我不想使用 WaitForSingleObject
等待,或者至少不想在 CreateProcess
之后立即等待。 CreateProcess
包含在我的另一个名为“ExecuteProcess”的函数中。 CreateProcess
返回后,ExecuteProcess
也返回,ExecuteProcess
返回时,栈上定义的所有输入参数都会被销毁。
来自 MSDN 的示例 Creating a Child Process with Redirected Input and Output似乎以与我类似的方式使用 CreateProcess
。 CreateProcess
在函数 CreateChildProcess
中调用,所有输入参数都在“CreateChildProcess”的堆栈上定义,WaitForSingleObject
也未使用。
最佳答案
没有。进程参数被复制到新进程的地址空间中。您可以随时摆脱它们。
关于C++ WIN API : When creating a child process using CreateProcess, 是否需要使输入参数具有全局生命周期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159619/
我是一名优秀的程序员,十分优秀!