2013-01-06 58 views
-1

我从下面的程序得到以下错误:CreateProcess的失败(3)CreateProcess()函数。 GetLastError()返回3

int __cdecl main(int argc, char **argv) 
{ 
    USES_CONVERSION; 
    string name_of_bitmap; 
    cout << "Name of file: "; 
    cin >> name_of_bitmap; 
    string arguments = "F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe " + name_of_bitmap; 
    const char * nob; 
    nob = arguments.c_str(); 
    std::wstring stemp = s2ws("F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe"); 
    LPCWSTR path = stemp.c_str(); 
    // runing simulation display process 
    STARTUPINFO si; 
    PROCESS_INFORMATION pi; 

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

    // Start the child process. 
    if (!CreateProcess(path, 
     A2W(nob) , 
     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 
     ) 
    { 
     printf("CreateProcess failed (%d).\n", GetLastError()); 
     Sleep(2000); 
     return 1; 
    } 
} 

我是新来的过程,不能找出我做错了。我读this并做了以下string arguments = "\"F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe\" " + name_of_bitmap;std::wstring stemp = s2ws("\"F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe\" ");然后得到错误123,如果我NULL第一个参数CreateProcess(NULL,我得到失败2.请帮助。

编辑

std::wstring s2ws(const std::string& s) 
{ 
    int len; 
    int slength = (int)s.length() + 1; 
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); 
    wchar_t* buf = new wchar_t[len]; 
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); 
    std::wstring r(buf); 
    delete[] buf; 
    return r; 
} 
+1

请使用正确的代码缩进。 –

+0

通过检查你传递给'CreateProcess'的参数来调试。 's2ws'的使用在这里是相当不必要的。只需使用'path = L“...”'。哪个离开'A2W'。我们无法猜测那是什么。 –

回答

1

错误2是

ERROR_FILE_NOT_FOUND 
2 (0x2) 
The system cannot find the file specified. 

要么你指定的路径是不存在或s2ws是做给你的字符串的东西时髦的文件。我们可以看到s2ws吗?

+0

从文件属性复制的路径如下所示:F:\ windowsqnx \ show_simulation \ Debug。我将这个函数添加到上面的问题中。 – Lukasz

+0

F:\ windowsqnx \ show_simulation \ Debug或F:\ windowsqnx \ maps \ show_simulation \ Debug?你确定文件存在,你的进程有权限读取该目录吗?尝试对文件存在进行测试。下面是一个示例:http://stackoverflow.com/questions/3828835/how-can-we-check-if-a-file-exists-or-not-using-win32-program – spartygw

+0

该死!抱歉。我是一个白痴,它应该是'“\”F:\\ windowsqnx \\ show_simulation \\ Debug \\ show_simulation.exe \“”+ name_of_bitmap;' – Lukasz

1

BAD: “... \ show_simulation.exe \”

好: “... \ show_simulation.exe”

尝试键入 “show_simulation.exe \” 在命令行 - 你”看看我的意思:)

它看起来像s2ws()可能是罪魁祸首附加不需要的尾部斜杠。

+0

我做了你告诉我的F:\\ windowsqnx \\ maps \\ show_simulation \\ Debug \\ show_simulation.exe“+ name_of_bitmap;'但我仍然得到相同的错误。 – Lukasz

相关问题