Code:
HANDLE hIWrite,hIRead,hIWriteTmp,hOWrite,hORead,hOReadTmp,hErrWrite;
SECURITY_ATTRIBUTES sa;
sa.nLength =sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=true;
sa.lpSecurityDescriptor=NULL;
// Create the child output pipe
CreatePipe(&hOReadTmp,&hOWrite,&sa,NULL);
DuplicateHandle(GetCurrentProcess(), hOWrite,GetCurrentProcess(), &hErrWrite, 0,
TRUE, DUPLICATE_SAME_ACCESS);
// Create the child input pipe
CreatePipe(&hIRead,&hIWriteTmp,&sa,NULL);
DuplicateHandle(GetCurrentProcess(), hOReadTmp,GetCurrentProcess(), &hORead, 0,
FALSE, DUPLICATE_SAME_ACCESS);
DuplicateHandle(GetCurrentProcess(), hIWriteTmp,GetCurrentProcess(), &hIWrite, 0,
FALSE, DUPLICATE_SAME_ACCESS);
CloseHandle(hOReadTmp);
CloseHandle(hIWriteTmp);
STARTUPINFO si;
memset(&si,0,sizeof(STARTUPINFO));
si.cb=sizeof(STARTUPINFO);
si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.hStdOutput=hOWrite;
si.hStdInput=hIRead;
si.hStdError=hErrWrite;
si.wShowWindow=SW_HIDE;
char app[] ="gdb --annotate=2 -silent";
PROCESS_INFORMATION pi={0};
CreateProcess(NULL,&app[0],NULL,NULL
,true,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
HANDLE hPid=pi.hProcess;
CloseHandle(pi.hThread);
CloseHandle(hOWrite);
CloseHandle(hIRead);
CloseHandle(hErrWrite);
char buf[1024]={0};
DWORD cbRead=0,cbWrite=0;
char *b="help\n";
WriteFile(hIWrite,b,strlen(b),&cbWrite,NULL);
while(1)
{
RtlZeroMemory(&buf[0],1024);SetLastError(0);
if(!ReadFile(hORead,&buf,1023,&cbRead,NULL)||cbRead==0)
break;
SendMessage(m_hWndEdit,EM_SETSEL,-1,0);
SendMessage(m_hWndEdit,EM_REPLACESEL,FALSE,(LPARAM)(LPCTSTR)&buf[0]);
}