Hi, I want to get a startet with programming using WIN32, so I wrote a program that creates a process, but in the line of code where I create the process, the program gets an error, it doesn't work (abend). I do not know if the code in program 1 is incorrect or the code in the second program that must be created first. (I don’t know if the code in the first program after "createprocess" is correct, because I didn’t debug further, because I get an error in this line. (I tested it without cout, waitforobject and close handle but I didn’t work either )).
First program:
#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); }
The second program:
#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
Tyzak source share