tags:

views:

20

answers:

1

Hi, Im invoking console application from my MFC application through ShellExecuteEx(). After the exe get loading,i want to receive one test string form console apllication to MFC,if i cannot receive the string then i will close both MFC and Console application.

For this,i want to send any string or valu from console application to MFC. I dont know how to do that.

char szFile[20]={0},szDir[500]={0}; 
memset(szFile,0,20);    
memset(szDir,0,500);    
strcpy(szFile,szModelName); 
strcat(szFile,".EXE");  
sInfo.lpFile = szFile;  
sInfo.hwnd = NULL;//this;   
sInfo.lpParameters ="MODEL";
strcat(szDir,"\\Sources\\");    
sInfo.lpDirectory = szDir;  
sInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
sInfo.cbSize = sizeof(SHELLEXECUTEINFO);
sInfo.lpVerb = "open";
sInfo.nShow  =  SW_HIDE;
sInfo.hwnd   =  NULL;
BOOL bFlag = ShellExecuteEx(&sInfo);

Console application coding

int main( int argc , char *argv[] )
{   char str[50];   
strcpy(str,argv[1]);    
getch();        
}
+1  A: 

If you want to send data from a console application back to the application that invoked it, you need to print to stdout and have the invoking application read that output. Don't use ShellExecuteEx, use a wrapper that deals with the file descriptor redirection that is necessary for you. Have a look at http://www.codeguru.com/Cpp/misc/misc/article.php/c321 . The CRedirect class in there does what you need.

Roel