도스용 프로그램을 실행시...
화면에 출력되는 문자열을 catch해서
RichEdit나 그런곳에 뿌릴 방법이 없을가요? (다이렉트로..)
CreateProcess를 사용해서 해 했는데..
다 실행되고 나서... 화면에 뿌리더군요..
'
참고로 소스는 아래와 같습니다.
void RunConsoleApp(char *runfile)
{
STARTUPINFO sui;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
HANDLE hReadPipe, hWritePipe;
char Buffer[4000];
DWORD dwRead;
char rpath[256];
char rpath1[256];
unsigned long exitcode;
sprintf(rpath,"%s\\FELT.EXE",ExePath,runfile);
sprintf(rpath1,"FELT.EXE %s",runfile);
TPREForm *Child;
Child = new TPREForm(Application);
Child->Show();
Child->BitBtn1->Enabled=false;
//setup the stdout
//fist create the sec attrib
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
//create pipe handles
CreatePipe(&hReadPipe, &hWritePipe, &sa, 2500000);
if (hReadPipe == INVALID_HANDLE_VALUE ::
hWritePipe == INVALID_HANDLE_VALUE){
smessage("Not a valid Handle for STDOUT");
return;
}
//setup the start up info
memset(&sui, 0, sizeof(STARTUPINFO));
sui.cb = sizeof (STARTUPINFO);
sui.dwFlags = STARTF_USESTDHANDLES : STARTF_USESHOWWINDOW;
sui.wShowWindow = SW_HIDE;
sui.hStdOutput = hWritePipe;
if (!CreateProcess (rpath, rpath1, NULL, NULL, true, NULL, NULL, NULL, &sui, &pi)){
smessage("Could not create process");
return;
}
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess,&exitcode );
smessage("exitcode = %d",exitcode);
//read from the pipe and put it in the richedit
bool ReadLoopDone = false;
Child->RichEdit1->Lines->Clear();
while (!ReadLoopDone){
memset(Buffer, 0, 4000);
ReadFile(hReadPipe,
&Buffer,
sizeof(Buffer),
&dwRead,
NULL);
Child->RichEdit1->Lines->Add(String(Buffer));
Child->RichEdit1->Refresh();
if (dwRead < 4000) ReadLoopDone = true;
}
Child->BitBtn1->Enabled=true;
return;
}
이 방법말고 도스화면을 catch 해서 뿌릴방법이 없을까요?
물론 다이렉트로 말입니다.
참 smessage는 MessageBox 같은것입니다.
부탁드립니다... 고수님들..
|