gpt4 book ai didi

c++ - CreateProcess,第一个参数问题

转载 作者:行者123 更新时间:2023-11-27 22:29:22 25 4
gpt4 key购买 nike

我正在尝试创建一个名为 s2.exe 的进程。但是,我无法确定需要作为第一个参数传递的内容。我尝试输入进程所在位置的名称和位置,但我得到“错误 2 开始 CC”。第一个参数到底应该放什么? (根据 MSDN,它是模块的路径。)

int main()
{
PROCESS_INFORMATION po;
STARTUPINFO s;
GetStartupInfo (&s);

if(CreateProcess(L"c:/s2", NULL, NULL, NULL,
false, 0, NULL, NULL, &s, &po) == FALSE)
{
printf("Error %d starting CC\n", GetLastError());
return -1;
}
}

最佳答案

GetLastError() 返回的值 2 表示 ERROR_FILE_NOT_FOUND。需要传入c:/s2.exe,假设s2.exe实际在c:\盘中。

请注意 CreateProcess()lpApplicationName 参数的 MSDN 文档说:

The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed.


另请注意,void main() 不是标准的 C++。但是,int main() 是标准的 C++,允许您返回某种退出代码。 (我编辑了您的代码片段以反射(reflect)这一点。)

关于c++ - CreateProcess,第一个参数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4777259/

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