2

I have 2 Visual Studio C projects: The first is the mainly program, and the second project creates an input for the first one.

How can I perform automatically the second program before the mainly program is running?

( i.e. The second project will create the input before the first one read it, and I won't have to run the second program myself manually).

user3114639
  • 1,895
  • 16
  • 42
  • possible duplicate of [Running two projects at once in Visual Studio](http://stackoverflow.com/questions/3850019/running-two-projects-at-once-in-visual-studio) – Cody Gray - on strike May 04 '14 at 11:58

1 Answers1

0

You can only have one process starting automatically. Therefore, you can debug both by launching the second from the source code of the first one. On Windows, you will have to use the Win32 API, to include Windows.h and to call the CreateProcess() function. The second process should be attached automatically to the debugger. After the call to CreateProcess(), the first process can terminate safely. You can embrace it in a preprocessor condition if you do not want it on the release version.

#ifdef _DEBUG
     CreateProcess(...
#endif
  • 1
    Nah, you actually *can* have Visual Studio start multiple projects when beginning a debug session. See the answers to the linked question. – Cody Gray - on strike May 04 '14 at 11:59
  • Thanks for your reply. I don't want to use with WIN API because I need to keep on the cross platform principle. Also, using with processes isn't safe, because the first progress read the input which the second program create, so if the second process won't finish to create it, the first project will read incorrect data, – user3114639 May 04 '14 at 12:02
  • Those are not really arguments against Plantaquatix's answer. First, if you're writing a cross-platform app, you'd just use whatever library method wraps the platform-native way of starting a process. For example, in Qt, you'd use the `QProcess` class. Ultimately, though, on Windows, it's going to call `CreateProcess`. Second, Visual Studio is essentially going to call `CreateProcess`, too, so there's no guarantee that the data will be available for the first project. You're still going to have to deal with synchronization issues. It might be easier just to pass arguments on the command line. – Cody Gray - on strike May 04 '14 at 12:06