我用了这个方法
HINSTANCE  handle=EShellExecute(NULL,NULL,"abc.doc",NULL,NULL,SW_SHOW);
DWORD a=WaitForSingleObject((HANDLE)handle,INFINITE);
DOWRD b=GetLastError(a);
//老是返回错误,说是无效的句柄怎么回事啊

解决方案 »

  1.   

    用CreateProcess启动程序,最后的参数是一个PROCESS_INFORMATION结构,
    typedef struct _PROCESS_INFORMATION { // pi 
        HANDLE hProcess; 
        HANDLE hThread; 
        DWORD dwProcessId; 
        DWORD dwThreadId; 
    } PROCESS_INFORMATION; 
    PROCESS_INFORMATION pi;
    CreateProcess...
    WaitForSingleObject(pi.hProcess,INFINITE);
      

  2.   

    Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with no time-out interval may cause the system to become deadlocked. Two examples of code that indirectly creates windows are DDE and COM CoInitialize. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than WaitForSingleObject.
      

  3.   

    WaitForSingleObject该函数不能用来同步含有消息驱动的window程序
      

  4.   

    the return value from ShellExecute is not a process handleset up SHELLEXECUTEINFO, call ShellExecuteEx call, retrieve the process handle, thten call WaitForSingleObjectsee
    Q: How do I start a program, and halt execution of my current program, till that program exits?
    http://www.codeproject.com/system/newbiespawn.asp
      

  5.   

    好象进程关闭了之后HANDLE为空吧!
      

  6.   

    用Mutex应该可以实现
    在要等待的进程中创建一个命名的Mutex,在等待进程中定时OpenMutex,若失败,则要等待的进程已关闭
      

  7.   

    MsgWaitForMultipleObjects在SDK程序是改主循环。 在MFC程序中怎么用啊
      

  8.   

    MsgWaitForMultipleObjects问题我已解决,用winprotc.谢谢大家.