Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    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.