我测试好象是启动2个,但是实在是找不到2个啊
void CuiDlg::StartSync(CString param){
    CString s1;    int check  = checkStartSync();
    int ret;    setSyncCanceled(false);    // check credentials
    ClientSettings* cs = getRegConfig();
    CString user;
    CString password;
    user = cs->getAccessConfig().getUsername();
    password = cs->getAccessConfig().getPassword();    if(user.IsEmpty() || password.IsEmpty()){
        HwndFunctions::closePreviousMsgBox();
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ERROR_ENTER_CREDENTIALS);
        TimedMessageBox(GetSafeHwnd(), s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT), MB_OK | MB_ICONHAND, INFINITE);
        OnStartsyncEnded(0,0); // signal sync ended
        OnMenuComm();
        return; // we return from this so we don't lock the panes
    }
    else
      if (!isServerConfigured()) {
        HwndFunctions::closePreviousMsgBox();
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_TEXT_SET_FUNAMBOL_URL);
        TimedMessageBox(GetSafeHwnd(), s1, getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT), MB_OK | MB_ICONHAND, INFINITE);
        OnStartsyncEnded(0,0); // signal sync ended
        OnMenuComm();
        return; // we return from this so we don't lock the panes    } else if(check == 0) {
        // maybe the user deleted the mail account
        // so we refresh the mail and if there is no source to be synced, we return
        if(! isSyncEnabled())
            return; // no sync will be performed        ret = startProgram(SYNCAPP, param);  // start sync process
        if ( (ret == 0) || (ret == -5) ) {
            HwndFunctions::closePreviousMsgBox();
            s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_TEXT_STARTSYNC_NOT_FOUND);
            TimedMessageBox(GetSafeHwnd(), s1,getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT), MB_OK | MB_ICONHAND, INFINITE);
            OnStartsyncEnded(0,0); // signal sync ended
            return; // we return from this so we don't lock the panes
        } else {
            dlgCommandBar.nToolBarId = IDM_STOP;            
            if(!SHCreateMenuBar(&dlgCommandBar)){
                TRACE(_T("Cannot create command bar!"));
                return ;
            }
        }
    };    lstSources.SetItemState(-1, LVIS_SELECTED, LVIF_STATE);
    // lock panes so they cannot be selected
    lockPanes();
}
int startProgram(const wchar_t *app, const wchar_t *cmdline)
{
    PROCESS_INFORMATION procinfo;    wchar_t *path = NULL;
    path = toWideChar(getRegConfig()->getPath().c_str());
    wstring cmd;    if (path) {
        cmd += path;
        delete [] path;
    }
    cmd += TEXT("\\"); cmd += app;    LOG.debug("Running: %ls %ls\n", cmd.c_str(), cmdline);
    if( CreateProcess( cmd.c_str(), cmdline,
                        NULL, NULL, FALSE, 0,
                        NULL, NULL, NULL, &procinfo ) ) {
        return procinfo.dwProcessId;
    }
    else {
        //-- maybe the Registry entry is missing, trying startcmd()
        int pid = startcmd(app, cmdline);
        return pid;
    }
}
unsigned long startcmd(const WCHAR *app, const WCHAR *cmdline)
{
    const WCHAR *path = getProgramPath();
    PROCESS_INFORMATION procinfo;    WCHAR *cmd = new WCHAR[wcslen(path)+wcslen(app)+5];
    wsprintf(cmd, TEXT("%s\\%s"), path, app);    char dbg[200];
    sprintf(dbg, "Running: %ls %ls\n", cmd, cmdline);
    LOG.info("%s", dbg);
    if( CreateProcess( cmd, cmdline,
                       NULL, NULL, false, 0,
                       NULL, NULL, NULL, &procinfo ) ) {
        return procinfo.dwProcessId;
    }
    else
        return 0;
}

解决方案 »

  1.   

    CreateProcess()就是创建进程的,所以应该是两个,分别在startcmd()、startProgram()中
      

  2.   


    startcmd 是 startProgram的一个if分支选择,createporcess失败之后才会startcmd的。。
      

  3.   

    1、判断有没有用户名密码,没有退出,有则继续
    2、判断服务器有没有配置好,没有退出,有则继续
    3、通过 CreateProcess 启动程序,不成功的话就用获取程序路径然后再 CreateProcess 启动程序