I will try to explain my problem. I have an application-interface, in it we set the settings. There is also the main application that you need to run with those settings.
If I correctly represent everything, it is necessary to set an event in the interface application to press the "START" button - transfer these settings as parameters via the command line to the main application. If IT is possible, then how can this be realized? Or maybe there is another way?

    3 answers 3

    In my opinion, it is better to do so.

    You have a launcher (launcher), which should run the main program. In the launcher, for example, you allow the user to specify the settings for running the main program (for example, the screen resolution, window size, etc.). Then the launcher saves all settings to FILE and launches the main program. The main program at startup reads all the settings recorded by the launcher, from this file.

    If you want to use the command line, then you just need to launch the main program in the launcher with parameters, i.e. specify them after the name, for example:

    main_program.exe "1024x768" "100x300" 

    And in the main program to read the startup parameters, you need to refer to the args argument (in my opinion it is called this way) - an array containing "1024x768" and "100x300", the main procedure is the main procedure (entry point).

    • thank. perhaps I will do just that - Stasik Kovalenko
    • "The main program at startup reads all the settings recorded by the launcher from this file." There is only one nuance. When you first start the program directly settings may not be. Therefore, the program should correctly work out: or display an error message, or start with the default parameters. In this case, the configuration file may or may not be created. Also, the configuration can be written not to a file, but to the registry. But I cannot call this path 100% correct. - gecube

    Calling system () from the standard C library.

     char cmd[1024]; // Π½Ρƒ, для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π°, строка Ρ‚Π°ΠΊΠΎΠΉ Π΄Π»ΠΈΠ½Ρ‹ // сформируСм строку, ΠΊΠ°ΠΊ Ссли Π±Ρ‹ Π½Π°Π±ΠΈΡ€Π°Π»ΠΈ Π² консоли (с ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½Ρ‹ΠΌΠΈ ΠΈΠ· Π΄ΠΈΠ°Π»ΠΎΠ³Π° Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ) sprintf (cmd,"my_main_prog.exe %s %s %s",arg1,arg2,arg3); int exit_status = system(cmd); // Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΠΌ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ (см. man 3 system) // ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Π°Π΅ΠΌ ΠΊΠΎΠ΄ Π²ΠΎΠ·Π²Ρ€Π°Ρ‚Π°. 

    When forming a string for system (), one must take into account that some characters for the cmd interpreter (for Windows, for Unix, see sh) have a special meaning. For Unix, see man sh, for Windows, help cmd and help start are useful.

    • Thanks, it was useful too - Stasik Kovalenko

    In my programs I used the following function:

     int CreateWaitChildProcess(wchar__t *cmd, wchar__t *cmdline) { PROCESS__INFORMATION pi; // Set up members of the PROCESS__INFORMATION structure. ZeroMemory( &pi, sizeof(PROCESS__INFORMATION) ); DWORD ec; // Create the child process. if(!CreateProcess(cmd, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { ec = GetLastError(); return -1; } WaitForSingleObject(pi.hProcess, INFINITE); if(GetExitCodeProcess(pi.hProcess, &ec)) return ec; return -2; } 
    • creates a child process (the path to the executable file is given by the cmd argument) passing it the arguments to the cmdline line on the command line, waiting for the completion of the child process. If you do not need to wait for completion, you can simply remove the WaitForSingleObject () call, but in this case the completion code of the child process will also remain unknown, that is, you must also remove the GetExitCodeProcess () call. If you have more questions - ask.
    • You can instead use the CreateProcess function exec and its derivatives execl, execle, execlp, execlpe, execv, etc. - gecube