error by creating process

Posted by Tyzak on Stack Overflow See other posts from Stack Overflow or by Tyzak
Published on 2010-03-29T22:10:12Z Indexed on 2010/03/29 22:13 UTC
Read the original article Hit count: 371

Filed under:
|

hello i want to get startet with programming with WIN32, therefore i wrote a programm that creates a process but in the line of code where i create the process the programm gets an error an dosn't work (abend). i don't know if the code in programm 1 is wrong or the code in the second programm that should be created by the first. ( I don't know if the code in the first programm after "createprocess" is right because i didn't get further with debugging, because in this line i get the error.(i tested it without the cout,waitforobject and close handle but i didn't work either )).

First Programm:

#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

void main()
{

bool ret;
bool retwait;

STARTUPINFO startupinfo;
GetStartupInfo (&startupinfo);

PROCESS_INFORMATION pro2info;

    ret = CreateProcess(NULL, L"D:\\betriebssystemePRA1PRO2.exe", NULL, NULL, false, CREATE_NEW_CONSOLE, NULL,
        NULL, &startupinfo, &pro2info);


    cout<<"hProcess: "<<pro2info.hProcess<<endl;
    cout<<"dwProcessId: "<<pro2info.dwProcessId <<endl;

    retwait= WaitForSingleObject (pro2info.hProcess, 100);
    retwait= WaitForSingleObject (pro2info.hProcess, 100);

    CloseHandle (pro2info.hProcess);//prozesshandle schließen 

    retwait= WaitForSingleObject (pro2info.hProcess, 100);



ExitProcess(0);


} 

Seconde Programm:

#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

void main()
{


    int b;

    b=GetCurrentProcessId();

    cout<<b<<endl;
    cout<<"Druecken Sie Enter zum Beenden"<<endl;
    cin.get();
        //warten bis Benutzer bestätigt

    Sleep (700);
    ExitProcess(0);

    cout<<"test";
}

Thanks in advance

© Stack Overflow or respective owner

Related posts about Windows

Related posts about c++