在自己的程序中调用别的程序进行计算,算完后想看它的输出结果。  目前用的Winexec调的这个程序,但接下来调用NotePad 看它的输出结果时,发现这个程序还没算完,因此也没有结果。  由于我的计算任务是动态的,计算时间我没法控制,我不知道这个程序何时算完,才可以看它的结果。
   
   请问大家是不是有什么更好的办法。如果有源码就更好了。

解决方案 »

  1.   

    那你不能用winexec,要用createprocess 给你个简单例子AfxMessageBox("打开程序!!");
    HANDLE abc=CreateProcess(.....);  //你要打开的exe
    WaitForSingleObject(abc,-1);
    AfxMessageBox("程序关闭!!");
      

  2.   

    就用CreateProcess吧,对进程的控制比WinExec强多了
      

  3.   


    MSDN是这样写的void main( VOID )
    {
        STARTUPINFO si;
        PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );    // Start the child process. 
        if( !CreateProcess( NULL, // No module name (use command line). 
            "MyChildProcess", // Command line. 
            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.
        ) 
        {
            ErrorExit( "CreateProcess failed." );
        }    // Wait until child process exits.
        WaitForSingleObject( pi.hProcess, INFINITE );    // Close process and thread handles. 
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );
    }