-1

I get the following error from the program below: CreateProcess failed(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;
    }
}

I'm new to processes and can't figure out what I do wrong. I read this and did the following string arguments = "\"F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe\" " + name_of_bitmap; and std::wstring stemp = s2ws("\"F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe\" "); then getting the error 123 if I NULL the first parameter CreateProcess(NULL, I get the failure 2. Please help.

EDIT

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;
}
2
  • 1
    please use proper code indentation. Jan 6, 2013 at 19:05
  • Debug this by inspecting what parameters you are passing to CreateProcess. The use of s2ws is rather needless here. Just use path = L"...". Which leaves A2W. We can't guess what that is. Jan 6, 2013 at 19:47

3 Answers 3

2

Error 2 is

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

Either the path you specified is for a file that doesn't exist or s2ws is doing something funky to your string. Can we see s2ws?

4
  • the path copied from the file properties looks like this: F:\windowsqnx\show_simulation\Debug. I add the function to the question above.
    – Lukasz
    Jan 6, 2013 at 19:14
  • F:\windowsqnx\show_simulation\Debug or F:\windowsqnx\maps\show_simulation\Debug? Are you sure the file exists and your process had permission to read in that directory? Try testing that for file existence. Here's a sample: stackoverflow.com/questions/3828835/…
    – spartygw
    Jan 6, 2013 at 19:28
  • Damn! Sorry. I'm an idiot, it should be "\"F:\\windowsqnx\\show_simulation\\Debug\\show_simulation.exe\" " + name_of_bitmap;
    – Lukasz
    Jan 6, 2013 at 19:42
  • Glad you found it, you're not an idiot. We've all done something like that.
    – spartygw
    Jan 7, 2013 at 15:34
1

According to Windows error code documentation, error 2 means ERROR_FILE_NOT_FOUND and error 3 means ERROR_PATH_NOT_FOUND, both probably mean the exe is not where you told Windows it is.

1

BAD: "...\show_simulation.exe\"

GOOD: "...\show_simulation.exe"

Try typing "show_simulation.exe\" from a command line - you'll see what I mean :)

It looks like s2ws() might be the culprit appending the unwanted trailing slash.

1
  • I did what you told me "F:\\windowsqnx\\maps\\show_simulation\\Debug\\show_simulation.exe" + name_of_bitmap; but I still get the same error.
    – Lukasz
    Jan 6, 2013 at 19:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.