CreateProcess()

Hello,

The following code segment fails to launch the 'Calc.exe',
the calculator that comes with Windows, from within my
application:

STARTUPINFO si;

ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
CreateProcess("CALC", "", NULL, NULL, FALSE, 0,
NULL, NULL, &si, NULL);
...
...

Can anyone point to my mistake(s)?

Thanks a lot

Comments

  • 1. When some Win32 API fails you have to call 'GetLastError()' to find out why it is failed:
    [code]
    if (! CreateProcess (...)) {
    DWORD dwErrorCode = GetLastError ();
    // At this point go to MSDN online and open topic:
    // "Win32 Error Codes" - probably you will find some answers
    }
    [/code]
    2. You specify NULL as a pointer to process information.
    It can be a problem, but I am not sure... Try this:
    [code]
    PROCESS_INFORMATION pi;

    CreateProcess (..., &pi);
    [/code]
    3. You do not specify anything for how to show the main window of a starting application. Try this:
    [code]
    STARTUPINFO si;

    // Your code to initialize 'si'...
    si.wShowWindow = SW_SHOWNORMAL;
    si.dwFlags = STARTF_USESHOWWINDOW;

    CreateProcess (..., &si, &pi);
    [/code]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion