I'm trying executing a program and wait the output but this run under a thread but crashed the program when try wait the output with 'WaitForSingleObject' of CreateProcess().
also I want will close handle of thread created when finish the process created by 'CreateProcess'
class test{
public:
static void fun2(void * args){
/*...*/
if (!CreateProcess( NULL, Args, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &StartupInfo, &ProcessInfo)) {
return GetLastError();
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
ULONG rc;
if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)){
status = 0;
}
/*...*/
}
void fun1(){
/* ... */
HANDLE h = NULL;
h = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)fun2,&data,0,0);
if(h!=NULL){
printf("OK\n");
}
/* ... */
}
};
int main(){
test t;
t.fun1();
return 0;
}
std::thread
and the synchronization mechanisms available from there? – user8238559