Search code examples
c++arduinoserial-portconfiguration-fileslauncher

How can I pass information from a launcher to my program?


Here is the deal : I have created a data transfer program that sends info to my Arduino over Serial Port. I have also created a simple "launcher" program with a basic UI for the user to Select the COM Port and launch the program. It is basically just a Windows Forms Application with a DropDown Combo Box for the COM Port and a "Launch" Button that starts the Transfer Program.

The Launcher and the Transfer Program are separate, so I need a way for the Transfer Program to get the information of the Serial Port the user chooses on the Launcher before starting the program.

I've looked into config files, shared txt files etc. but found nothing but overly-complicated programs.

Any help would be appreciated!

Thanks,

Frazic


Solution

  • There are some ways to do that.
    1. Start your program with parameters using int main(int argc, char* argv[]) For more Information: How to parse command line parameters. And you can run your tool with: system("C:\\Program Files (x86)\\MyProgram\\transfer.exe ParamCOM");
    2. Put your transfer program in to a dll and call it from your GUI. With that solution you could transfer data in both directions while the transfer program is running.
    Walkthrough: Creating and Using a Dynamic Link Library (C++)
    3. Write the COM information from your GUI in a config.txt file before you call the transfer program. Now your transfer program could read the information from the file.
    4. Read memory from a different process using WinAPI. That is not a common way but it works. Searching for the right values is not that easy so I would prefer Point 1 - 3.