Example #1
0
static void Update_States(int iSelectedItem)
{
    TOOL* tool;
    LVITEM item = {};

    assert(hToolsPage);

    item.mask  = LVIF_PARAM;
    item.iItem = iSelectedItem;

    if (ListView_GetItem(hToolsListCtrl, &item)) // (item.iItem > -1) // TODO: corriger ailleurs ce genre de code...
    {
        LPWSTR lpszCmdLine = NULL;
        size_t numOfChars  = 0;
        tool = reinterpret_cast<TOOL*>(item.lParam);

        ListView_EnsureVisible(hToolsListCtrl, item.iItem, FALSE);

        Button_Enable(GetDlgItem(hToolsPage, IDC_BTN_RUN), TRUE);

        if (!*(wchar_t*)tool->m_AdvParam)
        {
            ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_HIDE);
            Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), FALSE);
        }
        else
        {
            Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), TRUE);
            ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_NORMAL);
        }

        if ( (Button_IsEnabled(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT))) &&
             (Button_GetCheck(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT)) == BST_CHECKED) )
        {
            numOfChars = BuildCommandLine(NULL, tool->m_Command, tool->m_AdvParam, 0);
            lpszCmdLine = (LPWSTR)MemAlloc(0, numOfChars * sizeof(WCHAR));
            BuildCommandLine(lpszCmdLine, tool->m_Command, tool->m_AdvParam, numOfChars);
        }
        else
        {
            numOfChars = BuildCommandLine(NULL, tool->m_Command, tool->m_DefParam, 0);
            lpszCmdLine = (LPWSTR)MemAlloc(0, numOfChars * sizeof(WCHAR));
            BuildCommandLine(lpszCmdLine, tool->m_Command, tool->m_DefParam, numOfChars);
        }

        SendDlgItemMessage(hToolsPage, IDC_TOOLS_CMDLINE, WM_SETTEXT, 0, (LPARAM)lpszCmdLine);

        MemFree(lpszCmdLine);
    }
    else
    {
        ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_HIDE);
        Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), FALSE);
        Button_Enable(GetDlgItem(hToolsPage, IDC_BTN_RUN), FALSE);
    }
}
Example #2
0
static int ExecuteCommand(const char *program, const char *arg)
{
    STARTUPINFOW startup_info;
    PROCESS_INFORMATION proc_info;
    wchar_t *command;
    int result = 0;

    command = BuildCommandLine(program, arg);

    // Invoke the program:

    memset(&proc_info, 0, sizeof(proc_info));
    memset(&startup_info, 0, sizeof(startup_info));
    startup_info.cb = sizeof(startup_info);

    if (!CreateProcessW(NULL, command,
                        NULL, NULL, FALSE, 0, NULL, NULL,
                        &startup_info, &proc_info))
    {
        result = -1;
    }
    else
    {
        // Wait for the process to finish, and save the exit code.

        result = WaitForProcessExit(proc_info.hProcess);

        CloseHandle(proc_info.hProcess);
        CloseHandle(proc_info.hThread);
    }

    free(command);

    return result;
}
Example #3
0
bool DcRawQT::GetRawImage(QString filename, QStringList args)
{
    int argc;
    char **argv;


	if(args.contains("-i")){
		args.removeOne("-i");
		qDebug("-i passed to GetRawImage");
	}

    args += filename;
    argc = BuildCommandLine(args, &argv);

	if(GetRawImage(argc, argv))
	{
		buildHistogram();

		return true;
	}

	return false;


}
Example #4
0
//-----------------------------------------------------------------------------
int ctkSlicerModuleTest(int argc, char * argv [] )
{
  QApplication app(argc, argv);
  ctkCommandLineParser parser;
  parser.addArgument("", "-F", QVariant::String);
  bool ok = false;
  QHash<QString, QVariant> parsedArgs = parser.parseArguments(argc, argv, &ok);
  if (!ok)
  {
    std::cerr << qPrintable(parser.errorString()) << std::endl;
    return EXIT_FAILURE;
  }
  QString xmlFileName = parsedArgs["-F"].toString();

  ctkPluginFrameworkFactory fwFactory;
  ctkPluginFramework* framework = fwFactory.getFramework();

  try {
    framework->init();
  }
  catch (const ctkPluginException& exc)
  {
    qCritical() << "Failed to initialize the plug-in framework:" << exc;
    exit(1);
  }


#ifdef CMAKE_INTDIR
  QString pluginPath = "/../plugins/" CMAKE_INTDIR "/";
#else
  QString pluginPath = "/plugins/";
#endif

  try
  {
    QString pluginLocation = "." + pluginPath + "liborg_commontk_slicermodule.dll";
    ctkPlugin* plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(pluginLocation));
    plugin->start(ctkPlugin::START_TRANSIENT);

    framework->start();

    ctkModuleDescription module;
    module = ReadModuleDescription( framework->getPluginContext(), xmlFileName );

    BuildCommandLine( framework->getPluginContext(), module );

  }
  catch (const ctkPluginException& e)
  {
    qCritical() << e.what();
  }

  return EXIT_SUCCESS;
}
Example #5
0
QByteArray *DcRawQT::GetImage(QString filename, QStringList args)
{

    int argc;
    char **argv;

	args += filename;
    argc = BuildCommandLine(args, &argv);

	return GetImage(argc, argv);

}
Example #6
0
QByteArray *DcRawQT::GetThumbNail(QString filename, QStringList args)
{
    QByteArray *imageArray = new QByteArray();
    int argc;
    char **argv;

    args += filename;
    argc = BuildCommandLine(args, &argv);

    if(0 == dcrawmain(argc, (const char **)argv, imageArray))
        return imageArray;

    return 0;

}
Example #7
0
HRESULT ExecCommon64(
    __in LPCWSTR wzArgumentsProperty,
    __in LPCWSTR wzTimeoutProperty,
    __in BOOL fLogCommand,
    __in BOOL fLogOutput
)
{
    HRESULT hr = S_OK;
    LPWSTR pwzCommand = NULL;
    DWORD dwTimeout = 0;
    BOOL fIsWow64Initialized = FALSE;
    BOOL fRedirected = FALSE;

    hr = WcaInitializeWow64();
    if (S_FALSE == hr)
    {
        hr = TYPE_E_DLLFUNCTIONNOTFOUND;
    }
    ExitOnFailure(hr, "Failed to intialize WOW64.");
    fIsWow64Initialized = TRUE;

    hr = WcaDisableWow64FSRedirection();
    ExitOnFailure(hr, "Failed to enable filesystem redirection.");
    fRedirected = TRUE;

    hr = BuildCommandLine(wzArgumentsProperty, &pwzCommand);
    ExitOnFailure(hr, "Failed to get Command Line");

    dwTimeout = GetTimeout(wzTimeoutProperty);

    hr = QuietExecEx(pwzCommand, dwTimeout, fLogCommand, fLogOutput);
    ExitOnFailure(hr, "QuietExec64 Failed");

LExit:
    ReleaseStr(pwzCommand);

    if (fRedirected)
    {
        WcaRevertWow64FSRedirection();
    }

    if (fIsWow64Initialized)
    {
        WcaFinalizeWow64();
    }

    return hr;
}
Example #8
0
QString DcRawQT::Identify(QString filename)
{
    QStringList args;

    args += "dcrawqt";
    args += "-i";
    args += "-v";
    args += filename;

    int argc;
    char **argv;//[2048];

    argc = BuildCommandLine(args, &argv);

    if(0 == dcrawmain(argc, (const char **)argv, new QByteArray()))
        return identifyInformation;

    return identifyInformation;
}
Example #9
0
/*
Calls dcrawqt and determines if the supplied filename is a supported raw image
file format
*/
bool DcRawQT::IsRaw(QString filename)
{
    QStringList args;

    args += "dcrawqt";
    args += "-i";
    args += "-v";
    args += "-c";
    args += filename;

    int argc;
    char **argv;

    argc = BuildCommandLine(args, &argv);

    if(0 == dcrawmain(argc, (const char **)argv, 0))
	{
        return true;
	}

    return false;
}
Example #10
0
HRESULT ExecCommon(
    __in LPCWSTR wzArgumentsProperty,
    __in LPCWSTR wzTimeoutProperty,
    __in BOOL fLogCommand,
    __in BOOL fLogOutput
)
{
    HRESULT hr = S_OK;
    LPWSTR pwzCommand = NULL;
    DWORD dwTimeout = 0;

    hr = BuildCommandLine(wzArgumentsProperty, &pwzCommand);
    ExitOnFailure(hr, "Failed to get Command Line");

    dwTimeout = GetTimeout(wzTimeoutProperty);

    hr = QuietExecEx(pwzCommand, dwTimeout, fLogCommand, fLogOutput);
    ExitOnFailure(hr, "QuietExec Failed");

LExit:
    ReleaseStr(pwzCommand);

    return hr;
}
Example #11
0
int main(int argc, char **argv)
{
    LONG               rc            =       RETURN_FAIL;
    STRPTR             filename,
                       commandLine   =       NULL,
                       ixWindow      =       DEFWINDOW;
    LONG               ixWait        =       0,
                       ixStack       =       DEFSTACK;
    BOOL               ixUShell      =       DEFUSHELL;
    BPTR               oldlock       = (BPTR)-1,
                       dirlock       = (BPTR)-1,
                       window        =       NULL;
    struct DiskObject *dobj          =       NULL;

    D(bug("IconX argc %d\n", argc));

    if (argc != 0)
    {
	displayMsg(ERROR_REQUIRED_ARG_MISSING);
	goto exit;
    }

    struct WBStartup *startup = (struct WBStartup *) argv;
    if (startup->sm_NumArgs < 2)
    {
	displayMsg(ERROR_REQUIRED_ARG_MISSING);
	goto exit;
    }
    
    D(bug("[IconX] startup->sm_NumArgs: %d\n", startup->sm_NumArgs));

    dirlock  = startup->sm_ArgList[1].wa_Lock;
    filename = startup->sm_ArgList[1].wa_Name;

    oldlock = CurrentDir(dirlock);

    /* query diskobject for tooltypes */
    dobj = GetDiskObject(filename);
    if (dobj == NULL)
    {
	struct EasyStruct es = {sizeof(struct EasyStruct), 0,
	    "Error", "IconX\nGetDiskObject failed for:\n%s", "OK"};
	EasyRequest(0, &es, 0, filename);
	goto exit;
    }

    if (dobj->do_Type == WBPROJECT)
    {
	const STRPTR *toolarray = (const STRPTR *)dobj->do_ToolTypes;
	STRPTR s;
	if ((s = FindToolType(toolarray, "WINDOW")))
	{
	    ixWindow = s;
	}
	if ((s = FindToolType(toolarray, "STACK")))
	{
	    ixStack = atol(s);
	}
	if ((s = FindToolType(toolarray, "USERSHELL")))
	{
	    if (MatchToolValue(s, "NO"))
	    {
		ixUShell = FALSE;
	    }
	}
	if ((s = FindToolType(toolarray, "WAIT")))
	{
	    ixWait += atol(s) * 50;
	}
	if ((s = FindToolType(toolarray, "DELAY")))
	{
	    ixWait += atol(s);
	}
    }
    else
    {
	displayMsg(ERROR_OBJECT_WRONG_TYPE);
	goto exit;
    }
    
    if (ixWait <= 0)
	ixWait = DEFWAIT;

    if (ixStack <= 4096)
	ixStack = DEFSTACK;
    
    D(bug("wait %d stack %d usershell %d window %s\n", ixWait, ixStack, ixUShell, ixWindow));

    D(bug("Building command line\n"));
    commandLine = BuildCommandLine(startup);
    if (commandLine == NULL)
    {
	displayMsg(IoErr());
	goto exit;
    }
    D(bug("[IconX] commandLine: '%s'\n", commandLine));

    window  = Open(ixWindow, MODE_OLDFILE);
    if (window == NULL)
    {
	/* try to open default window */
	window = Open(DEFWINDOW, MODE_OLDFILE);
    }

    if (window)
    {
	D(bug("[IconX] window ok\n"));
	struct TagItem tags[] =
	{
	    { SYS_Asynch,      FALSE        },
	    { SYS_Background,  TRUE         },
	    { SYS_Input,       (IPTR)window },
	    { SYS_Output,      (IPTR)NULL   },
	    { SYS_Error,       (IPTR)NULL   },
	    { SYS_UserShell,   ixUShell     },
	    { NP_StackSize,    ixStack      },
	    { TAG_DONE,        0            }
	};

	rc = SystemTagList(commandLine, tags);
	if (rc == -1)
	{
	    displayMsg(IoErr());
	    rc = RETURN_FAIL;
	}
    }
    else
    {
	displayMsg(IoErr());
	goto exit;
    }

    Delay(ixWait);
    rc = RETURN_OK;

exit:
    Close(window);
    FreeDiskObject(dobj);

    if (oldlock != (BPTR)-1)
	CurrentDir(oldlock);

    return rc;
}
Example #12
0
/*
* Returns file descriptor of the read-pipe or -1 on error.
*/
void ScriptController::StartProcess(int* pipein, int* pipeout)
{
	CString workingDir = m_workingDir;
	if (workingDir.Empty())
	{
		workingDir = FileSystem::GetCurrentDirectory();
	}

	const char* script = m_args[0];

#ifdef WIN32
	char* cmdLine = m_cmdLine;
	char cmdLineBuf[2048];
	if (!*m_cmdLine)
	{
		BuildCommandLine(cmdLineBuf, sizeof(cmdLineBuf));
		cmdLine = cmdLineBuf;
	}

	debug("Starting process: %s", cmdLine);

	WString wideWorkingDir = FileSystem::UtfPathToWidePath(workingDir);
	if (strlen(workingDir) > 260 - 14)
	{
		GetShortPathNameW(wideWorkingDir, wideWorkingDir, wideWorkingDir.Length() + 1);
	}

	// create pipes to write and read data
	HANDLE readPipe, readProcPipe;
	HANDLE writePipe = 0, writeProcPipe = 0;
	SECURITY_ATTRIBUTES securityAttributes = { 0 };
	securityAttributes.nLength = sizeof(securityAttributes);
	securityAttributes.bInheritHandle = TRUE;

	CreatePipe(&readPipe, &readProcPipe, &securityAttributes, 0);
	SetHandleInformation(readPipe, HANDLE_FLAG_INHERIT, 0);

	if (m_needWrite)
	{
		CreatePipe(&writeProcPipe, &writePipe, &securityAttributes, 0);
		SetHandleInformation(writePipe, HANDLE_FLAG_INHERIT, 0);
	}

	STARTUPINFOW startupInfo = { 0 };
	startupInfo.cb = sizeof(startupInfo);
	startupInfo.dwFlags = STARTF_USESTDHANDLES;
	startupInfo.hStdInput = writeProcPipe;
	startupInfo.hStdOutput = readProcPipe;
	startupInfo.hStdError = readProcPipe;

	PROCESS_INFORMATION processInfo = { 0 };

	std::unique_ptr<wchar_t[]> environmentStrings = m_environmentStrings.GetStrings();

	BOOL ok = CreateProcessW(nullptr, WString(cmdLine), nullptr, nullptr, TRUE,
		NORMAL_PRIORITY_CLASS | CREATE_NEW_PROCESS_GROUP | CREATE_UNICODE_ENVIRONMENT,
		environmentStrings.get(), wideWorkingDir, &startupInfo, &processInfo);
	if (!ok)
	{
		DWORD errCode = GetLastError();
		char errMsg[255];
		errMsg[255 - 1] = '\0';
		if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, errCode, 0, errMsg, 255, nullptr))
		{
			PrintMessage(Message::mkError, "Could not start %s: %s", *m_infoName, errMsg);
		}
		else
		{
			PrintMessage(Message::mkError, "Could not start %s: error %i", *m_infoName, errCode);
		}
		if (!FileSystem::FileExists(script))
		{
			PrintMessage(Message::mkError, "Could not find file %s", script);
		}
		if (wcslen(wideWorkingDir) > 260)
		{
			PrintMessage(Message::mkError, "Could not build short path for %s", workingDir);
		}
		CloseHandle(readPipe);
		CloseHandle(readProcPipe);
		CloseHandle(writePipe);
		CloseHandle(writeProcPipe);
		return;
	}

	debug("Child Process-ID: %i", (int)processInfo.dwProcessId);

	m_processId = processInfo.hProcess;
	m_dwProcessId = processInfo.dwProcessId;

	// close unused pipe ends
	CloseHandle(readProcPipe);
	CloseHandle(writeProcPipe);

	*pipein = _open_osfhandle((intptr_t)readPipe, _O_RDONLY);
	if (m_needWrite)
	{
		*pipeout = _open_osfhandle((intptr_t)writePipe, _O_WRONLY);
	}

#else

	int pin[] = {0, 0};
	int pout[] = {0, 0};

	// create the pipes
	if (pipe(pin))
	{
		PrintMessage(Message::mkError, "Could not open read pipe: errno %i", errno);
		return;
	}
	if (m_needWrite && pipe(pout))
	{
		PrintMessage(Message::mkError, "Could not open write pipe: errno %i", errno);
		close(pin[0]);
		close(pin[1]);
		return;
	}

	*pipein = pin[0];
	*pipeout = pout[1];

	std::vector<char*> environmentStrings = m_environmentStrings.GetStrings();
	char** envdata = environmentStrings.data();

	ArgList args;
	std::copy(m_args.begin(), m_args.end(), std::back_inserter(args));
	args.emplace_back(nullptr);
	char* const* argdata = (char* const*)args.data();

#ifdef DEBUG
	debug("Starting  process: %s", script);
	for (const char* arg : m_args)
	{
		debug("arg: %s", arg);
	}
#endif

	debug("forking");
	pid_t pid = fork();

	if (pid == -1)
	{
		PrintMessage(Message::mkError, "Could not start %s: errno %i", *m_infoName, errno);
		close(pin[0]);
		close(pin[1]);
		if (m_needWrite)
		{
			close(pout[0]);
			close(pout[1]);
		}
		return;
	}
	else if (pid == 0)
	{
		// here goes the second instance

		// only certain functions may be used here or the program may hang.
		// for a list of functions see chapter "async-signal-safe functions" in
		// http://man7.org/linux/man-pages/man7/signal.7.html

		// create new process group (see Terminate() where it is used)
		setsid();

		// make the pipeout to be the same as stdout and stderr
		dup2(pin[1], 1);
		dup2(pin[1], 2);
		close(pin[0]);
		close(pin[1]);

		if (m_needWrite)
		{
			// make the pipein to be the same as stdin
			dup2(pout[0], 0);
			close(pout[0]);
			close(pout[1]);
		}

#ifdef CHILD_WATCHDOG
		write(1, "\n", 1);
		fsync(1);
#endif

		chdir(workingDir);
		environ = envdata;

		execvp(script, argdata);

		if (errno == EACCES)
		{
			write(1, "[WARNING] Fixing permissions for", 32);
			write(1, script, strlen(script));
			write(1, "\n", 1);
			fsync(1);
			FileSystem::FixExecPermission(script);
			execvp(script, argdata);
		}

		// NOTE: the text "[ERROR] Could not start " is checked later,
		// by changing adjust the dependent code below.
		write(1, "[ERROR] Could not start ", 24);
		write(1, script, strlen(script));
		write(1, ": ", 2);
		char* errtext = strerror(errno);
		write(1, errtext, strlen(errtext));
		write(1, "\n", 1);
		fsync(1);
		_exit(FORK_ERROR_EXIT_CODE);
	}

	// continue the first instance
	debug("forked");
	debug("Child Process-ID: %i", (int)pid);

	m_processId = pid;

	// close unused pipe ends
	close(pin[1]);
	if (m_needWrite)
	{
		close(pout[0]);
	}
#endif
}
Example #13
0
Argument::Argument(int argc, char** const & argv) {
  BuildCommandLine(argc, argv);
}
Example #14
0
int Run(LPTSTR lpstrCmdLine = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
	// vds: >>
	HANDLE hOneInstanceMutex = CreateMutex(NULL, FALSE, _T("ConsoleOnInstanceMutex"));
	DWORD oneInstanceResult = GetLastError();
	bool bOneInstance = oneInstanceResult == ERROR_ALREADY_EXISTS; // vds:
	HWND hPrevConsole = FindWindow(MainFrame::GetWndClassInfo().m_wc.lpszClassName, NULL);
	// vds: <<

	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	wstring			strConfigFile(L"");
	wstring			strWindowTitle(L"");
	vector<wstring>	startupTabs;
	vector<wstring>	startupDirs;
	vector<wstring>	startupCmds;
	vector<wstring>	postedCmds; // vds: posted commands
	vector<bool> reusePreviousTabs; // vds: sessions
	int				nMultiStartSleep = 0;
	wstring			strDbgCmdLine(L"");
	WORD			iFlags = 0; // vds

	ParseCommandLine(
		lpstrCmdLine, 
		strConfigFile, 
		strWindowTitle, 
		startupTabs, 
		startupDirs, 
		startupCmds, 
		postedCmds, 
		nMultiStartSleep, 
		strDbgCmdLine,
		iFlags); // vds

	if (strConfigFile.length() == 0)
	{
		strConfigFile = wstring(L"console.xml"); // vds
//		strConfigFile = wstring(L"%APPDATA%\Console\console.xml");
//		strConfigFile = Helpers::GetModulePath(NULL) + wstring(L"console.xml");
//		strConfigFile = wstring(::_wgetenv(L"APPDATA")) + wstring(L"\\Console\\console.xml"); // vds
	}

	if (!g_settingsHandler->LoadSettings(Helpers::ExpandEnvironmentStrings(strConfigFile)))
	{
		//TODO: error handling
		return -1;
	}

	// vds: >>
	if (g_settingsHandler->GetBehaviorSettings().oneInstanceSettings.bAllowMultipleInstances && !(iFlags & CLF_REUSE_PREV_INSTANCE))
		bOneInstance = false;

	if (iFlags & CLF_FORCE_NEW_INSTANCE)
		bOneInstance = false;
	// vds: <<

	// vds: sessions >>
	bool reuseTab = g_settingsHandler->GetBehaviorSettings().oneInstanceSettings.bReuseTab;
	while (reusePreviousTabs.size() < startupTabs.size()) {
		reusePreviousTabs.push_back(reuseTab);
	}
	// vds: sessions <<

	// vds: sessions >>
	if (!bOneInstance) {
		SessionsSettings& sessionsSettings = g_settingsHandler->GetSessionsSettings();
		if (sessionsSettings.bRestoreTabs) {
			for (unsigned int j = 0; j < sessionsSettings.sessionDataVector.size(); ++j) {
				shared_ptr<SessionData> sessionData = sessionsSettings.sessionDataVector[j];

				startupTabs.insert(startupTabs.begin() + j, sessionData->strTabTitle);
				startupDirs.insert(startupDirs.begin() + j, sessionData->strWorkingDir);
				startupCmds.insert(startupCmds.begin() + j, L"");
				postedCmds.insert(postedCmds.begin() + j, L"");
				reusePreviousTabs.insert(reusePreviousTabs.begin() + j, false);
			}
		}
	}
	// vds: sessions <<

	// create main window
	NoTaskbarParent noTaskbarParent;
	MainFrame wndMain(strWindowTitle, startupTabs, startupDirs, startupCmds, postedCmds, reusePreviousTabs, nMultiStartSleep, bOneInstance, strDbgCmdLine); // vds:

	if (!g_settingsHandler->GetAppearanceSettings().stylesSettings.bTaskbarButton && !bOneInstance) // vds:
	{
		noTaskbarParent.Create(NULL);
	}

	if (wndMain.CreateEx(noTaskbarParent.m_hWnd) == NULL)
	{
		ATLTRACE(_T("Main window creation failed!\n"));
		return 1;
	}

	// vds: >>
	// vds: This variable has to be in the scope of the theLoop.Run() call otherwise the message is destroyed before it arrive to destination.
	wstring rebuildCommandLine;
	if (!bOneInstance) {
		wndMain.ShowWindow(nCmdShow);
	}
	else {
		// Give 3 seconds to exchange the DDE messages.
		wndMain.SetTimer(TIMER_TIMEOUT, 3000, NULL);
		rebuildCommandLine = BuildCommandLine(
			strConfigFile, 
			strWindowTitle, 
			startupTabs, 
			startupDirs, 
			startupCmds, 
			postedCmds,
			nMultiStartSleep, 
			strDbgCmdLine,
			iFlags);

#ifdef USE_COPYDATA_MSG
		// Search for running instance of console
		if (hPrevConsole) {
			COPYDATASTRUCT stCopyData;
			stCopyData.dwData = eEC_NewTab;
			stCopyData.cbData = (rebuildCommandLine.size() + 1) * sizeof(wchar_t);
			stCopyData.lpData = reinterpret_cast<void*>(const_cast<wchar_t*>(rebuildCommandLine.c_str()));

			SendMessage(hPrevConsole, WM_COPYDATA, 0, (LPARAM)(LPVOID)&stCopyData);
		}
#else
		::PostMessage(wndMain.m_hWnd, WM_SEND_DDE_COMMAND, reinterpret_cast<WPARAM>(hPrevConsole), reinterpret_cast<LPARAM>(rebuildCommandLine.c_str()));
#endif
	}
	// vds: <<
	int nRet = theLoop.Run();

	if (noTaskbarParent.m_hWnd != NULL) noTaskbarParent.DestroyWindow();

	_Module.RemoveMessageLoop();

	// vds: >>
	if (hOneInstanceMutex) {
		CloseHandle(hOneInstanceMutex);
		hOneInstanceMutex = NULL;
	}
	// vds: <<

	return nRet;
}