请问如何在程序中调用外部的可执行程序

解决方案 »

  1.   

    WinExec("f:\\temp\\do.exe");
    ShellExecute(AfxGetMainWnd()->m_hWnd, "open", "f:\\temp\\do.exe", NULL, NULL, SW_SHOWNORMAL);
    ShellExecuteEx(...)
      

  2.   

    ShellExecute()
    ShellExecuteEx()
    WinExec()CreateProcess()
      

  3.   

    so many ways :system
    WinExec
    ShellExecute
    CreateProcess
      

  4.   

    CreateProcess灵活些,简单用ShellExecute就够了
    PROCESS_INFORMATION ProcessInfo; 
    STARTUPINFO StartupInfo; //This is an [in] parameter
    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
    char full[]="TXT2FAX DJ_Text.txt a.bfx";
    StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
    if(CreateProcess(NULL,full, NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo))
    WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
      

  5.   

    方法一:
    WinExec("notepad.exe,SW_SHOW");
    方法二:
    ShellExecute(NULL,"open","notepad.exe",NULL,NULL,SW_SHOWMAXIMIZED)
    方法三:
    STARTUPINFO si;
    ::ZeroMemory(&si,sizeof(STARTUPINFO));
    si.cb=sizeof(STARTUPINFO);
    PROCESS_INFORMATION pi;if(::CreateProcess(NULL,_T("notepad.exe"),NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi))
    {
        ::CloseHandle(pi.hThread);
        ::WaitForSingleObject(pi.hProcess);
    }