CreateRemoteThread in a child process
hi,
i am trying to create a new thread in a child process:
Code:
long WINAPI eThread(){
AllocConsole();
freopen("CONOUT$", "wb", stdout);
printf("ok\n");
}
Code:
if( !CreateProcess(
"C:\\WINDOWS\\System32\\calc.exe",
NULL,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
){
printf( "CreateProcess failed (%d).\n", GetLastError() );
}
else if(!CreateRemoteThread(pi.hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)eThread, 0, 0, 0)){
printf( "CreateRemoteThread failed (%d).\n", GetLastError() );
}
the calc.exe starts, but exit immediately with a fatal error. do i need other flags?
the error comes not from the AllocConsole etc - it doesn't matter what eThread executes, it exits all the time.
thx for help, stev