gpt4 book ai didi

c++ - CreateProcess() 无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-04 16:30:08 28 4
gpt4 key购买 nike

我使用这段代码来启动我的程序

     int _tmain(int argc, _TCHAR* argv[])
{
STARTUPINFO cif;
ZeroMemory(&cif,sizeof(STARTUPINFO));
PROCESS_INFORMATION pi;
if (CreateProcess(L"C:\\test\\test.exe",NULL,
NULL,NULL,FALSE,CREATE_UNICODE_ENVIRONMENT,NULL,NULL,&cif,&pi)==TRUE)
{
cout << "process" << endl;
cout << "handle " << pi.hProcess << endl;
}
system("pause");
return 0;
}

程序启动正常,但立即失败(没有响应而失败)。 CreateProcess 返回真。当我不是从代码启动 test.exe 时,它​​工作正常。

最佳答案

您必须将 STARTUPINFO 和 PROCESS_INFORMATION 的内存清零,并且必须设置 STARTUPINFO 结构的 cb 字段。

正在复制 sample code in the Microsoft documentation是一个很好的起点。

关于c++ - CreateProcess() 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984428/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com