1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void Arc_Redirect::createProcesses()
{
//TCHAR programName[]=TEXT("ping 127.0.0.1 -t");
TCHAR programName[]=TEXT("Hola.exe");
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.hStdError = outStd[0].hOutWrite;
si.hStdOutput = outStd[0].hOutWrite;
si.hStdInput = outStd[0].hInRead;
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
if(!CreateProcess(NULL,programName,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))
throw "Error: Could not start Program!";
// Create thread
outStd[0].hThreadRd = CreateThread(NULL,0,Arc_readPipe,(LPVOID)outStd[0].hOutRead,0,&outStd[0].threadIdRd);
outStd[0].hThreadWr = CreateThread(NULL,0,Arc_writePipe,(LPVOID)outStd[0].hInWrite,0,&outStd[0].threadIdWr);
if(outStd[0].hThreadRd == NULL || outStd[0].hThreadWr == NULL) throw "Error creating thread!";
// Cleanup the useless handles
if(!CloseHandle(pi.hThread) || !CloseHandle(pi.hProcess))
throw "Error: Could not CloseHandle();";
}
|