使用CreateProcess与相对路径

时间:2010-12-20 01:59:13

标签: c++ windows process winapi

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

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();


}

2 个答案:

答案 0 :(得分:5)

它看起来不像是我的相对路径。 \是当前驱动器的根文件夹。

答案 1 :(得分:5)

夫妻俩:

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