How do I get the command line arguments in mfc applications?

advertisements

I wish to have a small dialog based app which is passed command line parameters, so, using VC++6 I ran the app wizard and chose an MFC dialog application. This is not automatically equiped 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 the argc etc arguments go here. The app I just created does not have these.

As there is obviously a function which is the entry point to the app, 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 app, and thereby over a MB in size. Are there and app wizard template libraries that will allow me to make a non MFC dialog app?

Thank you


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 ATL COM wizard to create non MFC dialog app. (chose the .exe option, not .dll)