gpt4 book ai didi

c++ - 使用具有相对路径的 CreateProcess

转载 作者:可可西里 更新时间:2023-11-01 09:41:45 26 4
gpt4 key购买 nike

是否可以通过相对路径来创建我的子进程?这段代码可以编译,但会报错,因为我使用的是相对路径。

void Cminivideo3App::creerChildProcess(void)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

// Start the child process.
int retvalue = CreateProcess( TEXT("\..\Debug\traitement.exe"), // No module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
);

int lastError = GetLastError();


}

最佳答案

一些事情:

  1. 正如@Oswald 所说,\ 是当前驱动器的根文件夹,而不是相对路径。
  2. 你忘了转义你的反斜杠。你真的想要 TEXT("..\\Debug\\traitement.exe")

关于c++ - 使用具有相对路径的 CreateProcess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486350/

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