I wish to have a small dialog based application which is passed command line parameters, so, using VC++6 I ran the application wizard and chose an MFC dialog application.
This is not automatically equipped with command-line parameters. So I went to MSDN to refresh my memory on these. MSDN states that all C++ programs have either a main() or a wmain() function and that the argc, etc. arguments go here. The application I just created does not have these.
As there is obviously a function which is the entry point to the application, can I stick the arguments here? I did try this, but I am not convinced that I was actually editing the correct function. (Can I find the function which is acting as the main() function from the project settings or similar?)
Basically, how do I get my program to read command line parameters.
Also as a sideline. For a simple program, which this is, I really do not want to make it an MFC application, and thereby over a MB in size. Are there application wizard template libraries that will allow me to make a non-MFC dialog application?
If you want to pass command line arguments then you will have to define the main() function with two arguments. The first argument defines the number of command line arguments and the second argument is the list of command line arguments.
All the command line arguments are stored in a character pointer array called argv[ ].
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line.
Use GetCommandLine(), which returns the name of the file being executed, followed by the arguments.
The application member m_lpCmdLine (used like yourApp.m_lpCmdLine
) contains only the arguments.
There is also CWinApp::ParseCommandLine() that you may find useful.
Also try the ATL COM wizard to create a non-MFC dialog application (chose the .exe option, not .dll).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With